删除迁移文件后出现Django操作错误

2024-09-30 03:22:20 发布

您现在位置:Python中文网/ 问答频道 /正文

在我系统的早期,在我知道如何利用django的内置用户模型之前,我有自己的名为myUser的类,我打算将其用于相同的目的。我最终删除了这个,而使用了django的用户模型。有一段时间一切都很好。然后,我尝试将所有自定义模型的id更改为UUIDField,但语法错误,不幸的是,我只有在运行makemigrations和migrate之后才意识到这一点。我纠正了它,但仍然有一个bug,因为错误语法的UUIDField的迁移文件仍然在迁移中徘徊。不管怎样,这是我从谷歌搜索中了解到的。由于我不确定是哪个迁移文件导致了错误,我只是删除了最后5个迁移文件(事后看来,这不是我有过的最好的想法)。不幸的是,其中一个迁移文件涉及删除myUser模型

现在,无论何时尝试迁移,都会出现以下错误:

django.db.utils.OperationalError:没有这样的表:phoneBook\u myUser

这个错误似乎停止了我的任何新迁移。我在谷歌上搜索了一段时间,似乎我的两个选择是要么深入研究django的细节,并尝试在修复之前捣乱——考虑到我只使用django两周,我希望避免这种情况——要么重新设置所有内容,从头开始构建系统。这也不太理想

我有myUSer模型的备份版本。恢复、迁移、删除然后迁移是“安全的”,还是会造成更大的混乱?我是否可以采取其他措施来解决此问题

更新: 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

Tags: 文件djangopy模型autotypeconnectionlength
1条回答
网友
1楼 · 发布于 2024-09-30 03:22:20

我最终创建了一个新版本的项目,一个所有文件的完美副本,但有一个新的数据库,一切都正常工作

相关问题 更多 >

    热门问题