简体   繁体   中英

yii2 migrations not applying

I run ./yii migrate and get

No new migration found. Your system is up-to-date.

while my database is clean.

If I run ./yii migrate/create and then ./yii migrate successfully finds it and asks whether to apply it.

Also if I rename one of migrations which are not being applied

for example

m1 4 1111_051424_create_user_table` => m1 5 1111_051424_create_user_table

it is also being found by yii.

By default all information about applied migrations stored into table migration. Check it.

Also if I rename one of migrations which are not being applied

for example m141111_051424_create_user_table` => m151111_051424_create_user_table

Have you renamed class name too?

Configure the DB in common/config/main.php (I assume you use the advanced template), because the migrate do not see the fronted/config/main.php

see also the migration guide

First of all, check which migrations are already considered to be successful in your application. You can check it by getting a list of all successful migrations from the database:

SELECT * FROM `you_db_name`.`migration`;

If you see there your migration, then you have several ways to solve this problem.

1) Delete the record of your migration from the table migration.

2) Comment down function(if you need it), then down your migration, and then up your migration.

To down migration(revert data structures):

php yii migrate/down 1 

To up migration:

php yii migrate up

All this will work fine, if the file with the migration is written correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM