我想在我的 laravel 7.x 应用程序上使用两个模型:用户和图像:
# Users migration : 2014_10_12_000000_create_users_table.php
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();
});
# Images migration : 2020_03_27_121254_create_models_images_table
Schema::create('images', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('user_id')->unsigned;
$table->string('name');
$table->timestamps();
});
Schema::table('images', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
尝试迁移时收到以下错误:一般错误:1215 无法添加外键约束(SQL:alter table images
add constraint images_user_id_foreign
foreign key ( user_id
) references users
( id
) on delete cascade)
我已经在谷歌上搜索但没有成功,有人可以帮助我吗?
谢谢