我是迁移的新手,并试图创建两个带有外键的表,其中一个引用另一个中的id,但是我一般都无法添加键错误.有什么我想念的吗?
错误:
[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
码:
Schema::create('app_groups', function($table) {
$table->increments('id');
$table->string('app_name');
$table->unsignedInteger('app_group_id');
$table->timestamps();
});
Schema::create('app_to_bucket', function($table) {
$table->increments('id');
$table->unsignedInteger('app_group_id');
$table->unsignedInteger('bucket_id');
$table->timestamps();
});
Schema::table('app_to_bucket', function($table) {
$table->foreign('app_group_id')->references('app_group_id')->on('app_groups')->onDelete('cascade');
});
Run Code Online (Sandbox Code Playgroud)