Laravel uses bigInteger as type for the increments and so does foreign so stick to those types for all your primary keys and foreign keys.
May 1, 2020
3
Level 2
Foreign key constraint '...' are incompatible
Hi,
I'm trying to get Laravel Forge up and running, but it keep posting this error below. Tried to make foreign key and ID to be the same type (integer), but still getting the error.
What am I doing wrong here?
Migrating: 2019_08_03_164948_misc_wormgear
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 3780 Referencing column 'misc_id' and referenced column 'id' in foreign key constraint 'misc_wormgear_misc_id_foreign' are incompatible. (SQL: alter table `misc_wormgear` add constraint `misc_wormgear_misc_id_foreign` foreign key (`misc_id`) references `miscs` (`id`) on delete cascade)
public function up()
{
Schema::create('misc_wormgear', function (Blueprint $table) {
$table->increments('id');
$table->integer('misc_id')->unsigned();
$table->integer('wormgear_id')->unsigned();
$table->foreign('misc_id')->references('id')->on('miscs')
->onDelete('cascade');
$table->foreign('wormgear_id')->references('id')->on('wormgears')
->onDelete('cascade');
});
}
public function up()
{
Schema::create('wormgears', function (Blueprint $table) {
$table->integer('id');
...
$table->timestamps();
});
...
public function up()
{
Schema::create('miscs', function (Blueprint $table) {
$table->integer('id');
...
$table->timestamps();
});
# For mysql
DB::statement("ALTER TABLE miscs AUTO_INCREMENT = 311000");
}
Using version: 6.18
Level 73
3 likes
Please or to participate in this conversation.