如何使用 django-south 恢复删除的表?
我想清除数据库中的一个表,所以我删除了该表。通常我会执行manage.pysyncdb
来重新创建它。然而,答案这里说不要不再使用syncdb。那么,我该怎么办呢?
I wanted to clear out a table in my DB, so I dropped the table. Normally I would do manage.py syncdb
to re-create it. However, the answer here says not to use syncdb
anymore. So, what do I do instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有同样的问题。不确定这在所有情况下都有效,但这就是我所做的:
瞧!
您的里程可能会有所不同......
Had the identical problem. Not sure this works in all circumstances, but here's what I did:
Voila!
Your mileage may vary....
嗯,这次交流涵盖了我的问题:
我最终做的是注释掉我删除的有问题的模型,进行
schemamigration
,创建一个我删除的空无列表(这样 South 就可以删除一些东西),迁移
,然后取消注释模型,schemamigration
并再次迁移
。比仅仅删除表和syncdb更烦人,但是啊好吧。Hmm this exchange covers my very question:
What I ended up doing was commenting out the model that I dropped in question, doing a
schemamigration
, creating an empty no-column table of the one I dropped (so South has something to drop),migrate
ing, then un-commenting the model,schemamigration
andmigrate
ing again. A bit more annoying than just dropping the table andsyncdb
but ah well.确保您的所有迁移均已应用:
python manage.py migrate
告诉 Django 创建模型中的表:
python manage.pysyncdb
告诉 South 一切都在它应该在的地方:
python manage.py migrate appname --fake
这假设自您创建上次迁移以来,任何模型都没有发生任何变化。
Make sure all your migrations are applied:
python manage.py migrate
Tell Django to create the tables as they are in your models:
python manage.py syncdb
Tell South that everything is where it should be:
python manage.py migrate appname --fake
This assumes that nothing has changed in any of your models since you created your last migration.
我知道这个问题很旧,但我刚刚遇到这个问题,并认为我会发布我的解决方案,以防这对任何人有帮助。
models.py
文件夹。models.py
文件中剪切整个类。appname
--auto (这将创建另一个迁移,其中South
将识别并删除此表)。您可能需要在数据库中重新创建一个空白表,以便South
可以看到它。迁移
,该表应该从数据库中删除。models.py
文件中的位置。appname
--auto。 South 应该选择该表并允许您迁移appname
并且 South 应该将该表重新添加回您的数据库...以及列等,但没有数据,显然。 :)I know this issue is old, but I just ran into this issue and thought I'd post my solution in case this helps anyone.
models.py
folder where the database is.models.py
file.appname
--auto (this will create another migration whereSouth
will recognize to delete this table). You may need to recreate a blank table in you database soSouth
sees it.migration
and the table should drop from your database.models.py
file.appname
--auto. South should pick up the table and allow you to migrateappname
and South should re-add the table back into your databasse... with the columns and such again, but without the data, obviously. :)这是一个相当晚的回应,但对于那些会遇到同样问题的人(就像我一样)。
通常要删除由 South 管理的应用程序的 db_tables,您应该使用:
但是如果您在数据库中手动删除它们,请让 South 了解它
当然要重新创建表
It's a pretty late response but for people who will run into the same issue (like I did).
Normally to drop the db_tables for the app that is managed by south you should use:
But if you dropped them manually in the db let south know about it
And of course to recreate the tables