After runing migrations, php artisan command to add role_id to users table was successful (I confirmed this using: php artisan migrate:status ) but when i chek mysql users database, I am unable to find the foreign key of role_id in users table.
I had to start the whole project again to be sure it wasn't my fault. I have also done research online as to why this is happening and also watched your youtube video titled, "Laravel Migrations: Table created but foreign key failed" but no luck
PK
Povilas Korop
✓ Link copied!
Can you show me the code of your migration file for this?
Should be:
$table->foreignId('role_id')->constrained();
O
Oleksii
✓ Link copied!
is it justified to create separate table only for 2-10-N roles ? perhaps consts or enum is better ?
M
Modestas
✓ Link copied!
Yes! The key aspect when creating a separate table for roles is - flexibility. Sure, const or enum can do similar things, but over teh long run - you never know what will be needed :)
After runing migrations, php artisan command to add role_id to users table was successful (I confirmed this using: php artisan migrate:status ) but when i chek mysql users database, I am unable to find the foreign key of role_id in users table.
I had to start the whole project again to be sure it wasn't my fault. I have also done research online as to why this is happening and also watched your youtube video titled, "Laravel Migrations: Table created but foreign key failed" but no luck
Can you show me the code of your migration file for this?
Should be: