Changes between Version 1 and Version 5 of Ticket #33899

Aug 6, 2022, 6:17:48 AM (19 months ago)


  • Ticket #33899

    • Property Easy pickings set
    • Property Has patch set
    • Property Needs tests set
    • Property Triage Stage UnreviewedAccepted
    • Property Summary migrations.RemoveField causes OperationalError "no such column" upon migrationmigrations.RemoveField causes OperationalError "no such column" upon migration when db_index=True
  • Ticket #33899 – Description

    v1 v5  
    14143. Install app in project
    15154. Create a model
    16 5. Add field on model
    17 6. Make migrations
    18 7. Remove field
    19 8. Make migrations
     165. Add field on model, set `db_index=True`
     176. Make migrations: `$ python makemigrations`
     187. Remove field from model
     198. Make migrations: `$ python makemigrations`
     209. Apply migrations: `$ python migrate`
    21 The migration should fail.
     22The migration fails with the following error (for an app called `web`, with a model called `Entity` with a field called `attribute` for example):
     24 ```
     25Running migrations:
     26  Applying contenttypes.0001_initial... OK
     27  ...
     28  Applying sessions.0001_initial... OK
     29  Applying web.0001_initial... OK
     30  Applying web.0002_remove_entity_attribute...Traceback (most recent call last):
     31  File "/usr/local/lib/python3.10/site-packages/django/db/backends/", line 89, in _execute
     32    return self.cursor.execute(sql, params)
     33  File "/usr/local/lib/python3.10/site-packages/django/db/backends/sqlite3/", line 357, in execute
     34    return Database.Cursor.execute(self, query, params)
     35sqlite3.OperationalError: error in index web_entity_attribute_d22c3fcb after drop column: no such column: attribute
     38== Details
     40The above steps create a set of migrations where at the end a `RemoveField` migration is produced. Applying this migration fails for fields which had `db_index=True`. The example I attached uses a SlugField where `db_index` defaults to `True`, setting this parameter to False will apply the migration without this error.
     42I reproduced the error with the following field types: TextField, IntegerField, SlugField, CharField, URLField
Back to Top