我需要创建外键才能与表用户加入表簿。我知道user_id列必须是相同的类型,如果origin col是未签名的,也应该是未签名的,但应该没问题。两个表都是bigint(20)无符号的。但是我遇到一个错误:“ 外键约束的格式不正确”
以下是迁移代码:
public function up()
{
Schema::table('books', function (Blueprint $table) {
$table->unsignedBigInteger('user_id')->nullable()->index()->after('id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('SET NULL')->onUpdate('CASCADE');
});
}
这是用户表迁移
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
有人可以告诉我问题出在哪里吗?非常感谢。
答案 0 :(得分:0)
该问题是由表的默认MariaDB MyIsam引擎引起的。因此,我需要使用默认为InnoDB的新my.ini重新启动db,然后再次迁移所有表。