mpociot / teamwork

User to Team associations with invitation system for the Laravel 5 Framework
MIT License
1.07k stars 170 forks source link

Problem with migrations #121

Closed fabdelgado closed 4 years ago

fabdelgado commented 4 years ago

Hello, I have a problem with a migration.

I need an Emission to be able to have N - Teams, but when a migration is run, laravel says

SQLSTATE [HY000]: General error: 1215 Unable to add foreign key constraint (SQL: alter table emissions add constraintemissions_team_id_foreign foreign key (team_id) references teams (id) on delete cascade)

I don't understand if it is something from the package or what may be happening.

The order of execution is first Teamwork and then the migration of Emission.

Captura de Pantalla 2020-07-08 a la(s) 21 08 05
okaufmann commented 4 years ago

That's because the data type is incompatible. teams.id is an unsigned integer (not big integer) as defined in migrations here: https://github.com/mpociot/teamwork/blob/master/database/migrations/2016_05_18_000000_teamwork_setup_tables.php#L44

You need to use $table->integer('team_id)->unsigned()->nullable();. This should fix it.

fabdelgado commented 4 years ago

@okaufmann, it works thanks!