我是新来的迁移,并尝试创建2个表中的外键在一个引用另一个ID,但我得到一个通用失败,添加关键错误。有什么我失踪?Laravel迁移不会添加外键
错误:
[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');
});
为什么不在表创建时添加外键? – ollieread