简体   繁体   English

如何在Django 1.7中删除现有迁移

[英]How to delete existing migrations in Django 1.7

So i'm following the Tango with Django guide, specifically part 7.3.2. 因此,我正在遵循Django探戈指南,特别是第7.3.2部分 of the tutorial. 本教程。 After I ran the command python3 manage.py makemigrations rango , it won't let me re-populate the database using the populate script. 在运行命令python3 manage.py makemigrations rango ,它不会让我使用populate脚本重新填充数据库。 Instead I got the error: django.db.utils.OperationalError: no such column: rango_category.slug . 相反,我得到了错误: django.db.utils.OperationalError: no such column: rango_category.slug

Then, I tried to revert things back to normal by deleting all the slug code (so before 7.3 of the guide). 于是,我试图通过删除所有的恢复一切恢复正常slug代码(本指南的7.3之前的话)。 I made a migration after doing so, but then because the prior migration which added the slug category was never deleted, I can't use the migrate command to revert my changes because it throws an error when it tries to migrate using the old Added category slug migration. 我这样做后所作出的迁移,但后来因为里面添加了蛞蝓类迁移之前从来没有删除,我无法使用migrate命令,因为它时,它试图抛出一个错误恢复我的变化migrate使用旧的Added category slug迁移。 Even when I specifically point to the newest migration, it still gives me an error for the old one. 即使我特别指出了最新的迁移,它仍然给我一个旧迁移的错误。

Then, in an effort to fix things, I used a bunch of different migrate and makemigrations commands, including --empty, --fake, squashmigrations etc and now my migrations look unrecognizable. 然后,在努力解决的事情,我用了很多不同的migratemakemigrations命令,包括--empty, --fake, squashmigrations等,现在我看迁移面目全非。 Is there a way to just delete all these existing migrations and just start from a completely clean slate? 有没有一种方法可以删除所有这些现有迁移,并从完全干净的状态开始?

This is what migrate --list looks like now, for reference: 这是migrate --list现在的样子,以供参考:

admin [ ] 0001_initial auth [ ] 0001_initial rango [ ] 0001_squashed_0003_category_slug (3 squashed migrations) [ ] 0001_squashed_0005_auto_20150328_0917 (5 squashed migrations) contenttypes [ ] 0001_initial sessions [ ] 0001_initial

For a clean start. 一个干净的开始。

  • Delete the migrations folder inside rango 删除rangomigrations文件夹
  • delete database which created.Then restart your migration process 删除创建的数据库。然后重新启动迁移过程

您不需要删除迁移文件夹,只需删除迁移文件,而是将__init__.py保留在那里。

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

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