dimanche 6 août 2017

Laravel 5.4 - Foreign key statement incorrectly formed [references `players` ()]

I am creating a simple foreign key. The query created is unfortunately wrong and i am unable to understand why.

alter table `teams` add constraint `teams_captain_id_foreign` foreign key (`captain_id`) references `players` ()

As you can see () is empty. It should have column id in it.

My migration looks very simple.

    Schema::table('teams', function (Blueprint $table) {
        $table->integer( 'captain_id')->unsigned()->after('captain_name');
        $table->index('captain_id');

        // FOREIGN KEY
        $table->foreign('captain_id', 'teams_captain_id_foreign')->refrences('id')->on('players');
    });

Now the first answer will be to check data types and table. they all are same.

Players table

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

Teams table

`captain_id` int(10) unsigned NOT NULL,

Both tables are also of same type

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |

I cant figure out what is wrong. The order of migration is also correct. I created table team, then players, then another migration of name add_captain_id_to_teams

Please help



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2v9FjbR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire