Opened 11 years ago
Closed 10 years ago
#21890 closed Bug (fixed)
django.core.exceptions.FieldError: Local field ... in class ... clashes with field of similar name from base class ...
Reported by: | Claus Conrad | Owned by: | |
---|---|---|---|
Component: | Migrations | Version: | 1.7-alpha-1 |
Severity: | Normal | Keywords: | |
Cc: | lists@…, info@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Moving a field from a subclass to its base class results in the above error due to the operations being in the wrong order. Reordering the operations allowed me to run the migration.
Change History (5)
comment:1 by , 11 years ago
Cc: | added |
---|
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 11 years ago
Cc: | added |
---|
comment:4 by , 11 years ago
From what I have understood, the changes occur first in class Foo
, thus it now has a field baz
. Then when applying changes in class Bar
, when it sees that parent class is Foo
and Bar
has a field of same name as that in Foo
, it raises FieldError
.
What I think of solving this:
If such FieldError
arises, then it should be caught and then we can create a whole new Bar
or something like that.
Thoughts?
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This has since been fixed by the autodetector rewrite. You will lose data with this move, as it's a column being moved across tables; to avoid this, you would have to manually create a migration that made the new column, copied data across, and then removed the old column, and then gave the new column the correct name (it can't have it to start with as it would clash, like the original error here)
Hi,
I can reproduce the error you describer with the following models:
After creating the version, I run
makemigrations
, then change my models to the second version and runmakemigrations
again.After that, running
migrate
triggers the following error:Thanks.