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.
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>
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>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/27959#comment:3>