我正在使用Ramsey \ Uuid包切换到UUID主键,并且效果很好。到目前为止遇到的唯一问题是当我运行php artisan migrate:rollback将其更改回原始主键ID:
Illuminate \ Database \ QueryException:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法错误;检查与您的MariaDB服务器版本相对应的手册'CHARACTER SET utf8mb4 NOT NULL COLLATE附近使用的语法第1行的
utf8mb4_unicode_ci
'(SQL:ALTER TABLE model_has_roles更改model_id model_id BIGINT UNSIGNED AUTO_INCREMENT CHARACTER SETutf 8mb4 NOT NULL COLLATEutf8mb4_unicode_ci
)
我的代码:
public function up()
{
if(!Type::hasType('uuid')) {
Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
}
Schema::table('model_has_roles', function (Blueprint $table) {
$table->uuid('model_id')->change();
});
}
public function down()
{
Schema::table('model_has_roles', function (Blueprint $table) {
$table->bigIncrements('model_id')->change();
});
}
我在做什么错?
您似乎要解决此问题:https://github.com/doctrine/dbal/issues/3714
[共识是,在您的列定义中添加->charset(null)
是在短期内解决该问题的最佳方法。
尝试
public function down()
{
Schema::table('model_has_roles', function (Blueprint $table) {
$table->bigIncrements('model_id')->charset(null)->change();
});
}