简体   繁体   English

yii2迁移不适用

[英]yii2 migrations not applying

I run ./yii migrate and get 我运行./yii migrate并获取

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. 如果我运行./yii migrate/create ,然后./yii migrate成功找到它并询问是否应用它。

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 m1 4 1111_051424_create_user_table` => m1 5 1111_051424_create_user_table

it is also being found by yii. 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 例如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 在common / config / main.php中配置数据库(我假设您使用的是高级模板),因为迁移看不到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. 1)从表迁移中删除迁移记录。

2) Comment down function(if you need it), then down your migration, and then up your migration. 2)注释掉功能(如果需要),然后下降迁移,然后上升迁移。

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. 如果正确编写了要迁移的文件,那么所有这些都将正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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