#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.add51e9c94d2c7debf7abe669d9c626f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to