#35022: migration fails from index_together to models.Index
---------------------------------------------+------------------------
Reporter: Thomas Capricelli | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 5.0
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 |
---------------------------------------------+------------------------
As index_together is obsolated, i changed in my models.py:
{{{
- index_together = [
- ('name', 'host',)
- ]
+ indexes = [models.Index(fields=["name", "host"])]
}}}
makemigrations created what seems a legit migration:
{{{
# Generated by Django 5.0.1 on 2023-12-06 12:46
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('main', '0004_auto_20200327_0040'),
]
operations = [
migrations.RenameIndex(
model_name='list',
new_name='main_list_name_cbdf64_idx',
old_fields=('name', 'host'),
),
]
}}}
But the actual migration fails badly:
{{{
% ./manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, flatpages, main,
registration, sessions, sites
Running migrations:
Applying main.0005_rename_list_name_host_main_list_name_cbdf64_idx...
Traceback (most recent call last):
File "/home/orzel/hg/xxx/./manage.py", line 8, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python3.11/site-
packages/django/core/management/__init__.py", line 442, in
execute_from_command_line
utility.execute()
File "/usr/lib/python3.11/site-
packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python3.11/site-packages/django/core/management/base.py",
line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib/python3.11/site-packages/django/core/management/base.py",
line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/django/core/management/base.py",
line 106, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-
packages/django/core/management/commands/migrate.py", line 356, in handle
post_migrate_state = executor.migrate(
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-
packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-
packages/django/db/migrations/executor.py", line 167, in
_migrate_all_forwards
state = self.apply_migration(
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-
packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-
packages/django/db/migrations/migration.py", line 132, in apply
operation.database_forwards(
File "/usr/lib/python3.11/site-
packages/django/db/migrations/operations/models.py", line 1050, in
database_forwards
raise ValueError(
ValueError: Found wrong number (2) of indexes for main_list(name, host).
}}}
I'm currently testing and the database is sqlite3. Browsing the sqlite
file i can see 3 indices on this table: one unrelated (id) and two for
name_host : one "idx" and one "uniq".
My bet is that having both an index_together and a unique_together is ...
bad ? (my bad?).
Or maybe it just freaks out django ? It might be specific to sqlite.
--
Ticket URL: <https://code.djangoproject.com/ticket/35022>
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/0107018c3f8c75dd-e74880df-a016-445f-bfd4-f809b86ccb02-000000%40eu-central-1.amazonses.com.