迁移时将Laravel MYSQL更改为utf8mb4

时间:2019-01-02 18:38:28

标签: php mysql laravel

我使用Laravel 5.7,我想将当前的mysqldb更改为utf8mb4。

在我的迁移下面查找:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTickDataTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tick_data', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('coin_basis_id')->nullable();

            //...

            $table->timestamp('open_time')->nullable();
            $table->timestamp('close_time')->nullable();
            $table->timestamp('exchange_timestamp');
            $table->timestamps();
        });
    }

}

基本上,我想在创建表后ALTER,但是将DB::unprepared('ALTER TABLE tick_data CONVERT TO CHARACTER SET utf8mb4');添加到up()函数时出现以下错误:

  

默认字符集utf8mb4整理'u tf8mb4_unicode_ci')

何时最佳执行此语句?

感谢您的答复!

1 个答案:

答案 0 :(得分:-1)

您可以尝试在表创建后修改它:

Schema::table('tick_data', function (Blueprint $table) {
    $table->string('table_name') // Name of the colum
                ->nullable() // must not fill
                ->after('exchange_timestamp'); // after the column "exchange_timestamp"
});