Oct 29, 2024
0
Level 3
Laravel 11 migration does not create foreign key
I have a migration for pivot table which looks like this:
public function up()
{
if ( !Schema::hasTable($this->bundles_table) ) {
Schema::create($this->bundles_table, function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('bundle_description');
$table->integer('location_id')->unsigned()->index();
$table->tinyInteger('active')->unsigned()->nullable()->default(0);
$table->tinyInteger('deleted')->unsigned()->default(0);
$table->timestamps();
});
}
if ( !Schema::hasTable($this->bundles_super_locations_table) ) {
Schema::create($this->bundles_super_locations_table, function (Blueprint $table) {
$table->id();
$table->integer('super_location_id')->unsigned()->index();
$table->bigInteger('bundle_id')->unsigned()->index();
$table->tinyInteger('primary_bundle')->unsigned()->nullable()->default(0);
$table->timestamps();
$table->softDeletes();
$table->foreign('super_location_id')->references('id')->on($this->super_locations_table)->cascadeOnDelete()->cascadeOnUpdate();
$table->foreign('bundle_id')->references('id')->on($this->bundles_table)->cascadeOnDelete()->cascadeOnUpdate();
});
}
}
The migration creates the table with all columns but does not create foreign keys. No errors not messages everything end up with success but without FK. Engin of the table is InnoDB. Any idea what could be the problem?
Please or to participate in this conversation.