在为新项目创建数据库时,我以某种方式搞砸了我的迁移。我现在遇到了不适用的迁移问题:
Operations to perform:
Apply all migrations: wagtailusers, wagtailembeds, wagtailadmin, sessions, admin, wagtailcore, auth, contenttypes, wagtaildocs, taggit, wagtailsearch, home, wagtailforms, wagtailredirects, wagtailimages
Running migrations:
No migrations to apply.
基于this answer(和其他一些人),似乎我最好的办法是清除django_migrations
表格中的内容。所以我跑了:
DELETE FROM django_migrations WHERE app='wagtailusers';
并收到错误:
ERROR: relation "django_migrations" does not exist
django_migrations如何不存在?我究竟做错了什么?我基本上想要擦除数据库中的所有内容以及所有迁移并从头开始,但它显然比我怀疑的要复杂得多。 (有一种更简单的方法可以基本上重新开始数据库和迁移吗?)
修改
我尝试恢复一个应用并再次向前迁移。
我运行了./manage.py showmigrations wagtailusers
,显示了所有已应用的迁移:
wagtailusers
[X] 0001_initial
[X] 0002_add_verbose_name_on_userprofile
[X] 0003_add_verbose_names
[X] 0004_capitalizeverbose
然后,我使用./manage.py migrate wagtailusers zero
Operations to perform:
Unapply all migrations: wagtailusers
Running migrations:
Rendering model states... DONE
Unapplying wagtailusers.0004_capitalizeverbose... OK
Unapplying wagtailusers.0003_add_verbose_names... OK
Unapplying wagtailusers.0002_add_verbose_name_on_userprofile... OK
Unapplying wagtailusers.0001_initial... OK
showmigrations
然后显示所有未应用的内容。然后,我使用./manage.py migrate wagtailusers
:
Operations to perform:
Apply all migrations: wagtailusers
Running migrations:
Rendering model states... DONE
Applying wagtailusers.0001_initial... OK
Applying wagtailusers.0002_add_verbose_name_on_userprofile... OK
Applying wagtailusers.0003_add_verbose_names... OK
Applying wagtailusers.0004_capitalizeverbose... OK
在showmigrations
中检查所有内容。但是,当我再次进行迁移时,它似乎仍然认为缺少某些东西?
Operations to perform:
Apply all migrations: wagtailusers
Running migrations:
No migrations to apply.
答案 0 :(得分:0)
如果我正确地阅读此内容,我认为只是输出令人困惑? 你的步骤似乎是
manage.py migrate wagtailusers zero
manage.py migrate wagtailusers
,但也有效manage.py migrate
No migrations to apply
manage.py showmigrations
如果这是事件的确切顺序并且我已经正确理解了事情,那么是的,实际上你想要manage.py说。迁移引擎需要稍微查看是否存在任何迁移,并且必须计算相当数量的状态,以便它可以确定是否存在应该创建的迁移但是不存在迁移。如果您想要仔细检查这一点,那么[x]
应该会显示所有现有的import com.ximpleware.*;
public class queryAttr{
public static void main(String[] s) throws VTDException{
VTDGen vg= new VTDGen();
if (!vg.parseFile("input.xml", false))
return false;
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("//xml/ep/source/@type");
int i=0;
while((i = ap.evalXPath())!=-1){
system.out.println(" attr val ===>"+ vn.toString(i+1));
}
}
}
迁移,并将其显示为已应用。
希望我能正确理解你的问题。