#34856: Running tests with historical migrations that contain index together
fails
with TypeError.
-----------------------------------------+------------------------
Reporter: Sage Abdullah | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
When running tests against Django's `main` branch on a project that has a
historical migration that contains `index_together` (either via the
`AlterIndexTogether` operation or as part of a `CreateModel` operation),
running that migration fails with `TypeError: 'class Meta' got invalid
attribute(s): index_together`. This is the case even if the model has
already been updated to use `indexes` instead of `index_together` and new
migrations have been created to update it.
To reproduce:
- Install Django < 5.1
- Start a new project and a new app
- Create a model with `index_together` and run `makemigrations`
- or run `makemigrations` before adding `index_together` and run it
again so `AlterIndexTogether` operation is created, same result
- Write a test that uses the database (a simple test with `TestCase` and
not `SimpleTestCase` should suffice)
- Optional: Update the model to use `indexes` instead of `index_together`
and run `makemigrations`
- Install latest Django `main`
- Run `python manage.py test -v3` and it fails when applying the migration
that contains `index_together`
Reproducible example: https://github.com/laymonage/django-test-repro
This is likely because `"index_together"` has been removed from
`django.db.models.options.DEFAULT_NAMES` in
2abf417c815c20f41c0868d6f66520b32347106e. Meanwhile, the historical model
constructed by the migrations framework will try to build the model with
the `Meta.index_together` option.
I'm not sure if this is expected. If it is, then that means developers
have to update their old migrations to not use `index_together` at all,
which doesn't seem to be ideal.
If it is not, the solution might be to reintroduce `"index_together"` in
`DEFAULT_NAMES` even though it will be no-op. Not sure if that's all there
is to it, but I'm happy to make a PR for a start.
--
Ticket URL: <https://code.djangoproject.com/ticket/34856>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018ab2febac6-62ff44cc-13a7-4fca-955e-7b1b97954019-000000%40eu-central-1.amazonses.com.