我想使用修补程序来操纵我的项目的表,所以,我遇到的第一个问题是,我创建了一个utf8编码的数据库,之后,我运行我的迁移,那么创建的表使用utf8mb4_unicode_ci。他们不应该默认为utf8吗?如果是的话,我该如何改变?编译修补程序和Laravel
第二个问题是当我尝试在我的本地语言(巴西葡萄牙语)上插入单词时,使用修补程序,即时通讯获取由这些字符引起的错误。就像这样:
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))'
我必须让补锅匠接受我的本地语言或做我必须对项目进行任何改变enconding?
我后迁移代码:
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,所以我还挺丢失。
可以请您显示为您的代码,以便我们可以帮助 –
嗨,我用我的Post迁移代码和我在Tinker上做的事情编辑问题。 – churros