I am working with database migrations in Yii2.
I have a problem while migrating all the migrations into the database by running command i.e. yii migrate
The problem is that Yii try to creates the table first which has a foreign key of another table which is not created yet but already in the migration sequence. So the got the following error
- cannot create foreign key constraint
Example:
Table 1: Users (id, role_id, name, email) // role_id is the foreign key here
Table 2: Roles (id, title, status)
So how can I tell Yii that first migrate Roles table and then migrate Users table into the database. I have over 50 tables like that.
Thanks :)