zhangshine
V2EX  ›  Django

Django 1.7 调整一下 choices 的顺序居然需要做 migration

  •  
  •   zhangshine · Oct 20, 2014 · 4501 views
    This topic created in 4224 days ago, the information mentioned may be changed or developed.
    今天调整了一下choices的顺序, django竟然认为需要做一次migration。

    就像下面的代码,把CHOICES里的('First', 1) 和 ('Second', 2)调换一下顺序,然后运行./manage makemigrations, 产生了一个0002_auto_20141020_1019.py文件。


    源:
    ```
    CHOICES = [
    ('First', 1),
    ('Second', 2)
    ]


    class Mig(models.Model):
    choice = models.CharField(max_length=200, choices=CHOICES)
    ```

    0002:
    ```
    class Migration(migrations.Migration):

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

    operations = [
    migrations.AlterField(
    model_name='mig',
    name='choice',
    field=models.CharField(max_length=200, choices=[(b'Second', 2), (b'First', 1)]),
    preserve_default=True,
    ),
    ]
    ```

    So, 大家认为这是Django有意为之的还是没有优化好?
    2 replies    2014-10-20 20:23:43 +08:00
    ant_sz
        1
    ant_sz  
       Oct 20, 2014
    应该是没有优化好
    实际上是Field的任何一个参数改变,django都会检测到并生成一个migration。有些纯 Python 的参数如 blank 的改变也会导致检查到 migration
    zhangshine
        2
    zhangshine  
    OP
       Oct 20, 2014
    @ant_sz soga
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5114 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 09:44 · PVG 17:44 · LAX 02:44 · JFK 05:44
    ♥ Do have faith in what you're doing.