Opened 9 years ago

Closed 8 years ago

#25733 closed Bug (duplicate)

Change of inherited model's primary key not spotted by makemigrations

Reported by: Matthew Somerville Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal 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 have an inherited model - class Speaker(Person) - where Person is from a third party module. That module has updated, changing their ID from implicit to an explicit id CharField, but updating that module and trying to migrate fails because it says "Key columns "person_ptr_id" and "id" are of incompatible types: integer and character varying".

Presumably I need a migration in my module to change the implicit OneToOneField to be a CharField to match, but "makemigrations" doesn't find any change needed, it's still an integer.

Change History (4)

comment:1 by Matthew Somerville, 9 years ago

Looking further, some more interesting details arise. If I use "sqlmigrate", the output does include lines to drop the Speaker constraint, alter the Speaker's person_ptr_id and putting a constraint back; but running "migrate" does not include those lines, that constraint is not dropped and so you get the error I quote above when it tries to alter Person's ID to a CharField.

However, it actually wouldn't matter if those lines were present, because running the sqlmigrate output manually, you get a different constraint failure, the error then changes to be on the same line, but because of ForeignKey constraints on other models pointing at the Speaker table (ie. I have a Speech table with a speaker ForeignKey). As well as the direct constraint, all the constraints associated with the subclass model need to be dropped first too, it looks like.

So possibly two separate issues: sqlmigrate and migrate not having/running the same SQL, and not enough constraints being dropped to enable a key to be changed from implicit to a CharField.

comment:2 by Matthew Somerville, 9 years ago

Sorry, the last bit should also mention that the ForeignKeys to the subclass model (Speaker) need their fields changing to CharField too, that is missing along with the constraint dropping. Only the subclass model's field itself appears to be dealt with.

comment:3 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Simon Charette, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #25012.

Note: See TracTickets for help on using tickets.
Back to Top