django迁移地狱,丢了一张桌子。试图找回 [英] django migration hell, dropped a table. Tried to get it back
问题描述
因此,我在数据库中删除了一个表,并希望将其恢复。重新运行迁移后,错误表不存在。经过一番狩猎,我了解到我可以删除django_migrations中所有具有应用程序名称的应用程序。所以我做到了,重新运行迁移程序,然后开始处理未删除的表。
So I dropped a table in my database, and I want it back. Rerunning a migration gave errors table didn't exist. After some hunting I learned I could remove everything in my django_migrations that had app name my app. So i did that, reran migrations it started to work then griped about tables that were not dropped.
我不知道如何再次恢复一张表并保持
I have no idea how to just get the one table back again and keep everything as it was... anyway to do this?
我不在乎数据库中90%的数据,只关心几个表和字段。我放下的表不关心数据。
I don't care about 90% of the data in the database, only a few tables and fields. The table i dropped i cared nothing about the data.
推荐答案
首先检查 django_migrations
表。它包含有关已运行哪些迁移的数据。将此数据与实际的迁移文件进行比较,以了解哪些文件已运行。
Start by inspecting the django_migrations
table. It contains data about which migrations have already run. Compare this data to the actual migrations files to learn which ones have run or not.
最后,不要害怕删除 django_migrations中的行。
并修改原始迁移文件以重新创建所需的表。
Finally, don't be afraid to delete rows in django_migrations
and modify your original migrations files to recreate the tables you need.
这篇关于django迁移地狱,丢了一张桌子。试图找回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!