Opened 9 days ago
Last modified 8 days ago
#35991 assigned Bug
Migrations crash on SQLite when renaming part of CompositePrimaryKey.
Reported by: | Mariusz Felisiak | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I've created a sample project that tries to rename a column included in CompositePrimaryKey
. Unfortunately, it crashes:
$ python manage.py migrate test_one 0002 ... File "/django/db/backends/base/schema.py", line 509, in create_model sql, params = self.table_sql(model) ^^^^^^^^^^^^^^^^^^^^^ File "/django/db/backends/base/schema.py", line 290, in table_sql constraint_sqls.append(self._pk_constraint_sql(pk.columns)) ^^^^^^^^^^ File "/django/utils/functional.py", line 47, in __get__ res = instance.__dict__[self.name] = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/django/db/models/fields/composite.py", line 81, in columns return tuple(field.column for field in self.fields) ^^^^^^^^^^^ File "/django/utils/functional.py", line 47, in __get__ res = instance.__dict__[self.name] = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/django/db/models/fields/composite.py", line 77, in fields return tuple(meta.get_field(field_name) for field_name in self.field_names) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/django/db/models/fields/composite.py", line 77, in <genexpr> return tuple(meta.get_field(field_name) for field_name in self.field_names) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/django/db/models/options.py", line 685, in get_field raise FieldDoesNotExist( django.core.exceptions.FieldDoesNotExist: NewRelease has no field named 'name'
I've attached a sample project. I can prepare a patch in the coming days.
Attachments (1)
Change History (4)
by , 9 days ago
Attachment: | ticket_373_rename_column.zip added |
---|
comment:2 by , 9 days ago
Triage Stage: | Unreviewed → Accepted |
---|
Thanks for the report!
The issue likely lies in ProjectState.rename_field
and in MigrationAutoDetector.create_renamed_fields
which shouldn't generate the AlterField
against the composite primary key in the first place.
comment:3 by , 8 days ago
Owner: | set to |
---|---|
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
I've found other migrations that crashes in exactly the same way on SQLite.