[Django] #27959: Wrong output when alter field in sqlmigrate.

37 views
Skip to first unread message

Django

unread,
Mar 19, 2017, 6:11:40 AM3/19/17
to django-...@googlegroups.com
#27959: Wrong output when alter field in sqlmigrate.
--------------------------------------+----------------------------
Reporter: jinzhao | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Normal | Keywords: migrations
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+----------------------------
I start a container in docker image `python:2.7-slim` and test like this.

1. Use `django-admin startproject mysite` to start a project.
2. Use `./manage.py startapp app` to add a app.
3. Add a model in `app/models.py`.
{{{#!python
class Abcd(models.Model):
name = models.CharField(max_length=100)
}}}
4. Edit `mysite/settings.py`. Add `app.apps.AppConfig` to `INSTALLED_APPS`
5. Run `./manage.py makemigrations && ./manage.py migrate`.
6. Edit `app/models.py`. Change the max length of name field to 1000.
7. Run `./manage.py makemigrations && ./manage.py sqlmigrate app 0002`.

Here is the output.

{{{
ALTER TABLE "app_abcd" RENAME TO "app_abcd__old";
CREATE TABLE "app_abcd" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" varchar(1000) NOT NULL);
INSERT INTO "app_abcd" ("id", "name") SELECT "id", "name" FROM
"app_abcd__old";
DROP TABLE "app_abcd__old";
COMMIT;
}}}

It will create a new table, and drop all the data in the old table.

The migrate file seems correct. Here is
`app/migrations/0002_auto_20170319_1003.py`

{{{#!python
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-19 10:03
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

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

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

Django is installed by pip, django.VERSION is (1, 10, 6, u'final', 0).

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

Django

unread,
Mar 19, 2017, 7:09:20 AM3/19/17
to django-...@googlegroups.com
#27959: Wrong output when alter field in sqlmigrate.
----------------------------+--------------------------------------

Reporter: jinzhao | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Normal | Resolution:

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

Comment (by Tim Graham):

What is the bug? Creating a new table and copy over the data is expected
behavior as described in the
[https://docs.djangoproject.com/en/stable/topics/migrations/#sqlite SQLite
migration docs].

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

Django

unread,
Mar 19, 2017, 10:33:17 PM3/19/17
to django-...@googlegroups.com
#27959: Wrong output when alter field in sqlmigrate.
----------------------------+--------------------------------------

Reporter: jinzhao | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Normal | Resolution:

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

Comment (by jinzhao):

You are right. I didn't notice the difference between sqlite and mysql.
Sorry to create a wrong ticket.

Replying to [comment:1 Tim Graham]:


> What is the bug? Creating a new table and copy over the data is expected
behavior as described in the
[https://docs.djangoproject.com/en/stable/topics/migrations/#sqlite SQLite
migration docs].

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

Django

unread,
Mar 19, 2017, 10:34:49 PM3/19/17
to django-...@googlegroups.com
#27959: Wrong output when alter field in sqlmigrate.
----------------------------+--------------------------------------
Reporter: jinzhao | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Normal | Resolution: invalid

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

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


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

Reply all
Reply to author
Forward
0 new messages