[英]Django not creating database table after deleting migrations files and migration table
[英]Django - OperationalError after deleting migration files
在我系統的早期,在我知道如何使用 django 的內置用戶 model 之前,我有自己的 class 命名為 myUser,我打算將其用於相同目的。 我最終刪除了這個,而是使用了 django 的用戶 model。 有一段時間一切都很好。 然后我嘗試將所有自定義模型的 id 更改為 UUIDField,但語法錯誤,不幸的是,我在運行 makemigrations 和 migrate 后才意識到這一點。 我更正了它,但仍然存在一個錯誤,因為錯誤語法的 UUIDField 的遷移文件仍然在遷移中徘徊。 無論如何,這就是我從谷歌搜索中了解到的。 因為我不確定哪個遷移文件導致了錯誤,所以我只是刪除了最后 5 個遷移文件(事后看來,這不是我曾經有過的最好的主意)。 不幸的是,其中一個遷移文件涵蓋了 myUser model 的刪除。
現在,每當我嘗試遷移時,都會出現以下錯誤:
django.db.utils.OperationalError:沒有這樣的表:phoneBook_myUser
似乎這個錯誤正在阻止我通過任何新遷移到 go。 我已經用谷歌搜索了一段時間,似乎我的兩個選擇是深入了解 django 細節並嘗試解決問題,直到我修復它——考慮到我只使用 Django 2幾周-或重置所有內容並從頭開始構建系統。 這也不太理想。
我有 myUSer model 的備份版本。 是恢復它,遷移,刪除它,然后遷移“安全”,還是會造成更大的混亂? 我可以采取任何其他措施來解決此問題嗎?
更新:來自 python manage.py showmigrations 的結果:
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
phoneBook
[X] 0001_initial
[X] 0002_auto_20210707_1306
[X] 0003_informationrating_owner_ownerset_comments_connection/
_numbermetadata_source
[X] 0004_rename_comments_comment
[X] 0005_auto_20210707_1632
[X] 0006_auto_20210707_1634
[X] 0007_auto_20210707_1637
[X] 0008_alter_company_company_type
[X] 0009_owner_owner_type
[X] 0010_numbermetadata_published_at
[X] 0011_auto_20210713_0957
[X] 0012_auto_20210713_1014
[X] 0013_connectionrating
[X] 0014_informationrating
[X] 0015_delete_informationrating
[X] 0016_alter_owner_owner_type
[X] 0017_alter_owner_owner_type
[X] 0018_auto_20210713_1349
[X] 0019_auto_20210713_1525
[X] 0020_auto_20210713_1529
[X] 0021_auto_20210713_1533
[X] 0022_auto_20210713_1535
[X] 0023_alter_numbermetadata_owner_set_id
[X] 0024_auto_20210719_0948
[X] 0025_auto_20210719_1555
[ ] 0026_auto_20210720_1528
[ ] 0027_connection_connection_status
sessions
[X] 0001_initial
我的遷移文件:
0001_initial.py
0002_auto_20210707_1306.py
0003_informationrating_owner_ownerset_comments_connection/
_numbermetadata_source.py
0004_rename_comments_comment.py
0005_auto_20210707_1632.py
0006_auto_20210707_1634.py
0007_auto_20210707_1637.py
0008_alter_company_company_type.py
0009_owner_owner_type.py
0010_numbermetadata_published_at.py
0011_auto_20210713_0957.py
0012_auto_20210713_1014.py
0013_connectionrating.py
0014_informationrating.py
0015_delete_informationrating.py
0016_alter_owner_owner_type.py
0017_alter_owner_owner_type.py
0018_auto_20210713_1349.py
0019_auto_20210713_1525.py
0020_auto_20210713_1529.py
0021_auto_20210713_1533.py
0022_auto_20210713_1535.py
0023_alter_numbermetadata_owner_set_id.py
0024_auto_20210719_0948.py
0025_auto_20210719_1555.py
0026_auto_20210720_1528.py
0027_connection_connection_status.py
__init__.py
我最終創建了該項目的新版本,所有文件的完美副本,但使用了新數據庫,一切正常。
在您的應用程序中創建一個名為“migrations”的新文件夾,並在其中添加一個空的“ init .py”文件,然后進行遷移和遷移。 畢竟這確保你創建一個新的超級用戶來訪問管理頁面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.