Opened 8 years ago
Closed 8 years ago
#27959 closed Bug (invalid)
Wrong output when alter field in sqlmigrate.
Reported by: | jinzhao | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.10 |
Severity: | Normal | Keywords: | migrations |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I start a container in docker image python:2.7-slim
and test like this.
- Use
django-admin startproject mysite
to start a project. - Use
./manage.py startapp app
to add a app. - Add a model in
app/models.py
.class Abcd(models.Model): name = models.CharField(max_length=100)
- Edit
mysite/settings.py
. Addapp.apps.AppConfig
toINSTALLED_APPS
- Run
./manage.py makemigrations && ./manage.py migrate
. - Edit
app/models.py
. Change the max length of name field to 1000. - 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
# -*- 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).
Change History (3)
follow-up: 2 comment:1 by , 8 years ago
comment:2 by , 8 years ago
You are right. I didn't notice the difference between sqlite and mysql. Sorry to create a wrong ticket.
Replying to Tim Graham:
What is the bug? Creating a new table and copy over the data is expected behavior as described in the SQLite migration docs.
comment:3 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
What is the bug? Creating a new table and copy over the data is expected behavior as described in the SQLite migration docs.