为什么django 1.7为现场选择的变化创建迁移? [英] Why does django 1.7 creates migrations for changes in field choices?

查看:97
本文介绍了为什么django 1.7为现场选择的变化创建迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在版本1.7上观察到这种行为,但在以前的版本中已经观察到了这种行为,使用南移。

I have observed this behaviour on version 1.7 but not in previous versions using south migration.

eg。

class RedemptionCode(models.Model):
    EXPIRE_OPTIONS = (
        ('1 week', '1 Week'),
    )

    expire_option = models.CharField(max_length=255, choices=EXPIRE_OPTIONS)

当我添加更多选项:

EXPIRE_OPTIONS = (
    ('1 week', '1 Week'),
    ('2 weeks', '2 Weeks'),
    ('1 month', '1 Month'),
    ('1 day', '1 Day'),
)

并运行 makemigrations ,它为它创建一个迁移,来自 south background我认为应该说没有检测到任何更改,因为它不影响数据库模式。我不知道它的用途是什么:

and run makemigrations, it creates a migration for it, coming from south background I thought it should say no changes detected as it doesn't affects database schema. I don't know what purpose it serves:

class Migration(migrations.Migration):

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

    operations = [
        migrations.AlterField(
            model_name='redemptioncode',
            name='expire_option',
            field=models.CharField(max_length=255, choices=[('1 week', '1 Week'), ('2 weeks', '2 Weeks'), ('1 month', '1 Month'), ('1 day', '1 Day')]),
        ),
    ]


推荐答案

在提起机票并因重复关闭后,终于找到答案:

After raised the ticket and got closed due to duplication, finally found the answer:


这是设计。有几个原因,对我来说,历史上的点数据移动需要对模型进行完全准确的表示,包括所有的选项,不仅仅是影响数据库的那些。

This is by design. There are several reasons, not least of which for me that datamigrations at points in history need to have a full accurate representation of the models, including all their options not just those which affect the database.

参考:

  • https://code.djangoproject.com/ticket/22837
  • https://code.djangoproject.com/ticket/23581

这篇关于为什么django 1.7为现场选择的变化创建迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆