Skip to content
Advertisement

Django – OperationalError after deleting migration files

In the earliest days of my system, before i knew how to utilize django’s built-in User model, i had my own class named myUser which i intended to use for the same purpose. i ended up deleting this one and instead using django’s User model. all was fine for a while. then i tried to change the id of all my custom models to a UUIDField, and got the syntax wrong, which i unfortunately only realized after i ran makemigrations and migrate. i corrected it, but there was still a bug because the migration file of the wrongly-syntaxed UUIDField still lingered in migrations. that’s what i understood from googling for a while, anyway. since i wasn’t sure which migration file caused the error, i just deleted the last 5 migration files (in hindsight, not the best idea i’ve ever had). Unfortunately, one of those migration files were the one which covered the deletion of the myUser model.

now, whenever i try to migrate, i get the following error:

django.db.utils.OperationalError: no such table: phoneBook_myUser

it seems this error is stopping any of my new migrations to go through. i’ve googled for a while, and it seems my two options are to either dive deep down into django details and try to mess around until i fix it -which i had hoped to avoid, considering i’ve only been using Django for 2 weeks- or to reset everything and build the system from scratch. That is not too ideal either.

i have a backed-up version of the myUSer model. is reinstating it, migrating, deleting it and then migrating ‘safe’ or will it make an even bigger mess of things? Is there any other course of action i can take to fix this issue?

update: result from 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

my migration files:

    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

Advertisement

Answer

i ended up creating a new version of the project, a perfect copy of all the files, but with a new database, and everything works as it should.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement