21 | | The migration should fail. |
| 22 | The migration fails with the following error (for an app called `web`, with a model called `Entity` with a field called `attribute` for example): |
| 23 | |
| 24 | ``` |
| 25 | Running 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/utils.py", line 89, in _execute |
| 32 | return self.cursor.execute(sql, params) |
| 33 | File "/usr/local/lib/python3.10/site-packages/django/db/backends/sqlite3/base.py", line 357, in execute |
| 34 | return Database.Cursor.execute(self, query, params) |
| 35 | sqlite3.OperationalError: error in index web_entity_attribute_d22c3fcb after drop column: no such column: attribute |
| 36 | ``` |
| 37 | |
| 38 | == Details |
| 39 | |
| 40 | The 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. |
| 41 | |
| 42 | I reproduced the error with the following field types: TextField, IntegerField, SlugField, CharField, URLField |