简体   繁体   中英

How do you reset all migrations for an app in Django 1.7?

I am currently using postgres and I dropped a table in my events app. Now I'm getting all sorts of bugs when I try to run makemigrations like:

 return self.cursor.execute(sql, params)
    django.db.utils.ProgrammingError: relation "events_event" does not exist

How do you reset all migrations and models for an app in Django 1.7? Also is there an easy way to reset individual models within an app? In my case I would just like to drop the Event table then recreate it.

尝试从数据库的south_migrationhistory表中删除所有记录,并从/ migrations ...中删除所有迁移文件...(或仅删除有问题的迁移文件,因为如果删除所有迁移文件,则必须再次进行初始迁移)

1) If you want to start from initial migration:

In your app, there is a folder named migrations . Just delete all the files in that folder except the __init__.py file.That will reset migrations history for you.

Then when you run the makemigrations command, it will start from initial migration!

2) If you want to delete and/or add specific models then maybe you will need to either manually edit the migration files depending on your need. https://docs.djangoproject.com/en/1.7/topics/migrations/#migration-files Or you can delete specific migration files according to your requirement

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