[Django] #25733: Change of inherited model's primary key not spotted by makemigrations

4 views
Skip to first unread message

Django

unread,
Nov 11, 2015, 11:09:00 AM11/11/15
to django-...@googlegroups.com
#25733: Change of inherited model's primary key not spotted by makemigrations
----------------------------+--------------------
Reporter: dracos | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25733>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 11, 2015, 1:56:59 PM11/11/15
to django-...@googlegroups.com
#25733: Change of inherited model's primary key not spotted by makemigrations
----------------------------+--------------------------------------

Reporter: dracos | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by dracos):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25733#comment:1>

Django

unread,
Nov 11, 2015, 2:08:09 PM11/11/15
to django-...@googlegroups.com
#25733: Change of inherited model's primary key not spotted by makemigrations
----------------------------+--------------------------------------

Reporter: dracos | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by dracos):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25733#comment:2>

Django

unread,
Nov 13, 2015, 12:45:02 PM11/13/15
to django-...@googlegroups.com
#25733: Change of inherited model's primary key not spotted by makemigrations
----------------------------+------------------------------------

Reporter: dracos | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25733#comment:3>

Django

unread,
May 25, 2016, 3:40:42 AM5/25/16
to django-...@googlegroups.com
#25733: Change of inherited model's primary key not spotted by makemigrations
----------------------------+-------------------------------------
Reporter: dracos | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
Changes (by charettes):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #25012.

--
Ticket URL: <https://code.djangoproject.com/ticket/25733#comment:4>

Reply all
Reply to author
Forward
0 new messages