{{{
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/27456#comment:1>
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>
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>
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>
* 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>