简体   繁体   English

如何在Django 1.7中重置应用程序的所有迁移?

[英]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. 我目前正在使用postgres,并且在活动应用中放了一张桌子。 Now I'm getting all sorts of bugs when I try to run makemigrations like: 现在,当我尝试运行makemigrations时会遇到各种各样的错误:

 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? 如何在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: 1)如果要从初始迁移开始:

In your app, there is a folder named migrations . 在您的应用程序中,有一个名为migrations的文件夹。 Just delete all the files in that folder except the __init__.py file.That will reset migrations history for you. 只需删除该文件夹中除__init__.py文件之外的所有文件即可,这将为您重置迁移历史记录。

Then when you run the makemigrations command, it will start from initial migration! 然后,当您运行makemigrations命令时,它将从初始迁移开始!

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. 2)如果要删除和/或添加特定模型,则可能需要根据需要手动编辑迁移文件。 https://docs.djangoproject.com/en/1.7/topics/migrations/#migration-files Or you can delete specific migration files according to your requirement https://docs.djangoproject.com/zh-CN/1.7/topics/migrations/#migration-files或者您可以根据需要删除特定的迁移文件

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

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