I am new to migrations and attempting to create 2 tables with a foreign key in one referencing an id in the other but I am getting a general failure to add key error. is there something I am missing?
error:
[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
code:
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');
});