﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27959	Wrong output when alter field in sqlmigrate.	jinzhao	nobody	"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)."	Bug	closed	Migrations	1.10	Normal	invalid	migrations		Unreviewed	0	0	0	0	0	0
