[Django] #27456: Changing the unique paramater from True to False has no effect on MySQL

3 views
Skip to first unread message

Django

unread,
Nov 6, 2016, 3:23:36 PM11/6/16
to django-...@googlegroups.com
#27456: Changing the unique paramater from True to False has no effect on MySQL
--------------------------------------+------------------------
Reporter: Vadim | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords: mysql
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
Steps to reproduce:
1. Create a model:

{{{
from django.db import models

class TestModel(models.Model):
name = models.CharField(max_length=100, unique=True)
surname = models.CharField(max_length=50)
}}}
2. makemigrations && migrate

{{{
$ ./manage.py sqlmigrate testapp 0001_initial
BEGIN;
CREATE TABLE `testapp_testmodel` (`id` integer AUTO_INCREMENT NOT NULL
PRIMARY KEY, `name` varchar(100) NOT NULL UNIQUE, `surname` varchar(50)
NOT NULL);

COMMIT;
}}}

{{{
$ cat testapp/migrations/0001_initial.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='TestModel',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(unique=True, max_length=100)),
('surname', models.CharField(max_length=50)),
],
),
]
}}}

3. Set unique to False, makemigrations and migrate

{{{
from django.db import models

class TestModel(models.Model):
name = models.CharField(max_length=100, unique=False)
surname = models.CharField(max_length=50)
}}}

{{{
$ cat testapp/migrations/0002_auto_20161106_2004.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('testapp', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='testmodel',
name='name',
field=models.CharField(max_length=100),
),
]
}}}

{{{
$ ./manage.py sqlmigrate testapp 0002_auto_20161106_2004
}}}


{{{
mysql> show create table testapp_testmodel;
+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table
|
+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| testapp_testmodel | CREATE TABLE `testapp_testmodel` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`surname` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0,00 sec)
}}}

Notes:
It works well on SQLite
This bug also exists in 1.10

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

Django

unread,
Nov 6, 2016, 3:33:22 PM11/6/16
to django-...@googlegroups.com
#27456: Changing the unique parameter from True to False has no effect on MySQL
----------------------------+--------------------------------------

Reporter: Vadim | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: mysql | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

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

Django

unread,
Nov 6, 2016, 4:37:38 PM11/6/16
to django-...@googlegroups.com
#27456: Changing the unique parameter from True to False has no effect on MySQL
----------------------------+--------------------------------------

Reporter: Vadim | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: mysql | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by Shai Berger):

According to the description, after creating the second migration you only
ran the `sqlmigrate` command, not `migrate`. Is the error in your process
or your ticket description?

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

Django

unread,
Nov 6, 2016, 11:33:36 PM11/6/16
to django-...@googlegroups.com
#27456: Changing the unique parameter from True to False has no effect on MySQL
----------------------------+--------------------------------------

Reporter: Vadim | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: mysql | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by Vadim:

Old description:

New description:

{{{
from django.db import models

COMMIT;
}}}


class Migration(migrations.Migration):

dependencies = [
]

{{{
from django.db import models

class TestModel(models.Model):
name = models.CharField(max_length=100, unique=False)
surname = models.CharField(max_length=50)
}}}

4. makemigrations && migrate
5. Result is:


class Migration(migrations.Migration):

--

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

Django

unread,
Nov 6, 2016, 11:37:13 PM11/6/16
to django-...@googlegroups.com
#27456: Changing the unique parameter from True to False has no effect on MySQL
----------------------------+--------------------------------------

Reporter: Vadim | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: mysql | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by Vadim):

Replying to [comment:2 Shai Berger]:


> According to the description, after creating the second migration you
only ran the `sqlmigrate` command, not `migrate`. Is the error in your
process or your ticket description?

It was an error in my description. I updated it. Thank you!

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

Django

unread,
Nov 8, 2016, 7:13:38 AM11/8/16
to django-...@googlegroups.com
#27456: Changing the unique parameter from True to False has no effect on MySQL
----------------------------+--------------------------------------
Reporter: Vadim | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: worksforme

Keywords: mysql | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Tim Graham):

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


Comment:

I can't reproduce a problem. There's also a test in
[https://github.com/django/django/blob/ee1bf0e8b5f83274b7436d0a3f9240ca6c399a52/tests/schema/tests.py#L1678-L1686
schema/tests.py] that seems to cover this case. Please provide a test case
or point out where Django is at fault.

--
Ticket URL: <https://code.djangoproject.com/ticket/27456#comment:5>

Reply all
Reply to author
Forward
0 new messages