我试图使用tinker来操作我的项目的表,所以,我遇到的第一个问题是我已经创建了一个utf8编码的数据库,然后我运行我的迁移,然后,创建的表使用utf8mb4_unicode_ci。默认情况下,它们不是应该是utf8吗?如果是的话,我该怎么改变呢?
第二个问题是,当我试图在桌子上插入本地语言(巴西葡萄牙语)上的单词时,我会得到这些字符造成的错误。如下所示:
Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA1tulo ...' for column 'title' at row 1 (SQL: insert into `posts` (`title`, `body`, `updated_at`, `created_at`) values (Título 1, Corpo do primeiro post, 2017-10-09 14:58:40, 2017-10-09 14:58:40))'我必须让修补者接受我的当地语言,还是我必须在这个项目上做出任何改变?
我的发布迁移代码:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
// $table->charset = 'utf8';
// $table->collation = 'utf8_general_ci';
$table->increments('id');
$table->string('title');
$table->mediumText('body');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}在“修补程序”上我要这么做:
$post = new App\post();
$post->title = 'Título 1';
$post->body = 'Corpo do primeiro post';
$post->save();这是我第一次使用Laravel,所以我有点迷路了。
发布于 2017-10-09 15:46:06
尝试将这些行添加到您的“config/database.php”文件中,然后再试一次。
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'https://stackoverflow.com/questions/46649743
复制相似问题