为什么 django 1.7 会为字段选择的变化创建迁移? [英] Why does django 1.7 creates migrations for changes in field choices?
问题描述
我在 1.7 版上观察到了这种行为,但在以前使用南迁移的版本中没有.
I have observed this behaviour on version 1.7 but not in previous versions using south migration.
例如.
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
背景 我认为它应该说没有检测到更改,因为它不会影响数据库架构.我不知道它有什么用途:
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.
参考:
这篇关于为什么 django 1.7 会为字段选择的变化创建迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!