[Django] #25293: Multi-table inheritance with only related fields results in invalid migration on MySQL

7 views
Skip to first unread message

Django

unread,
Aug 19, 2015, 1:32:50 PM8/19/15
to django-...@googlegroups.com
#25293: Multi-table inheritance with only related fields results in invalid
migration on MySQL
----------------------------+--------------------
Reporter: hbielenia | 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
----------------------------+--------------------
This report may be a duplicate of
https://code.djangoproject.com/ticket/24424 , but since the scope is
somewhat different and proposed fix would not solve the issue, I decided
to report it separately.

On Django 1.8.2, I have following model:
{{{
class Client(User):
mailing_list = models.OneToOneField(SubscriberList, null=True,
default=None)
}}}

Using manage.py makemigrations generates following operations:

{{{
operations = [
migrations.CreateModel(
name='Client',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('user',
models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
),
migrations.RemoveField(
model_name='client',
name='id',
),
migrations.RemoveField(
model_name='client',
name='user',
),
migrations.AddField(
model_name='client',
name='mailing_list',
field=models.OneToOneField(null=True, default=None,
to='campaign.SubscriberList'),
),
migrations.AddField(
model_name='client',
name='user_ptr',
field=models.OneToOneField(parent_link=True,
auto_created=True, primary_key=True, default=0, serialize=False,
to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]
}}}

As you can see, the migration starts by removing implicit `id` and `user`
fields, to later substitute them with implicit `user_ptr` field that
serves both as foreign and primary key. Unfortunately,
`migrations.RemoveField` uses `ALTER TABLE` statements, and this code
attempts to delete all columns on the table, resulting in OperationalError
with MySQL 5.8:
`_mysql_exceptions.OperationalError: (1090, "You can't delete all columns
with ALTER TABLE; use DROP TABLE instead")`.

It looks to me like an unwanted behaviour.

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

Django

unread,
Aug 19, 2015, 2:14:49 PM8/19/15
to django-...@googlegroups.com
#25293: Multi-table inheritance with only related fields results in invalid
migration on MySQL
----------------------------+--------------------------------------

Reporter: hbielenia | 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 hbielenia):

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


Old description:

New description:

`django.db.utils.OperationalError: (1090, "You can't delete all columns


with ALTER TABLE; use DROP TABLE instead")`.

It looks to me like an unwanted behaviour.

--

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

Django

unread,
Aug 19, 2015, 3:06:03 PM8/19/15
to django-...@googlegroups.com
#25293: Multi-table inheritance with only related fields results in invalid
migration on MySQL
----------------------------+------------------------------------

Reporter: hbielenia | 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


Old description:

> `django.db.utils.OperationalError: (1090, "You can't delete all columns


> with ALTER TABLE; use DROP TABLE instead")`.
>
> It looks to me like an unwanted behaviour.

New description:

This report may be a duplicate of #24424 , but since the scope is somewhat

`django.db.utils.OperationalError: (1090, "You can't delete all columns


with ALTER TABLE; use DROP TABLE instead")`.

It looks to me like an unwanted behaviour.

--

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

Django

unread,
Aug 29, 2015, 3:12:14 PM8/29/15
to django-...@googlegroups.com
#25293: Multi-table inheritance with only related fields results in invalid
migration on MySQL
----------------------------+------------------------------------

Reporter: hbielenia | 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
----------------------------+------------------------------------

Comment (by abhaga):

I'm trying to reproduce it but for me, the following correct Migration is
being generated:

{{{
operations = [
migrations.CreateModel(
name='client',
fields=[
('user_ptr', models.OneToOneField(parent_link=True,
auto_created=True, primary_key=True, serialize=False,
to=settings.AUTH_USER_MODEL)),
('mailing_list', models.OneToOneField(null=True,
default=None, to='bug.SubscriberList')),
],
options={
'abstract': False,
'verbose_name': 'user',
'verbose_name_plural': 'users',
},
bases=('auth.user',),
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
}}}

Can you provide a complete set of model definitions that will reproduce
the issue?

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

Django

unread,
Aug 31, 2015, 11:04:51 AM8/31/15
to django-...@googlegroups.com
#25293: Multi-table inheritance with only related fields results in invalid
migration on MySQL
----------------------------+-------------------------------------
Reporter: hbielenia | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: needsinfo

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):

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


Comment:

We might be missing the state of the models before what is reported in the
description.

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

Reply all
Reply to author
Forward
0 new messages