gpt4 book ai didi

python - 为什么 Django 迁移更改字段 (AlterField) 是没有被触及的?

转载 作者:太空宇宙 更新时间:2023-11-03 11:44:37 24 4
gpt4 key购买 nike

当我进行迁移时 python manage.py makemigrations wall我在控制台中看到 Django (1.8.12) 告诉我一长串被触及的字段:

Migrations for 'wall':
0079_auto_20170302_0024.py:
- Add field periodic_task_interval to userproject
- Alter field bank_problems on bankireference
- Alter field bank_problems_category on bankireference
- Alter field bank_products on bankireference
- Alter field bank_products_category on bankireference
- Alter field extr_category on bankireference
- Alter field extr_words on bankireference
- Alter field neg_features on bankireference
- Alter field neutral_features on bankireference
- Alter field pos_features on bankireference
- Alter field tonality_category on bankireference
- Alter field tonality_words on bankireference
- Alter field bank_problems on fbpagepost
- Alter field bank_problems_category on fbpagepost
- Alter field bank_products on fbpagepost
- Alter field bank_products_category on fbpagepost
- Alter field extr_category on fbpagepost

......等等,靠近所有的字段就是ManyToManyField。我还检查了其他迁移,看起来像是随机选择的字段,因为我也看到了 tagulous.models.fields.TagField乃至models.TextField

但是,我确信 a 没有更改那些字段,甚至没有触及它们

这是 0079_auto_20170302_0024.py 中未触及字段的内容:

......
migrations.AlterField(
model_name='userproject',
name='description',
field=models.TextField(default='', verbose_name='Description', blank=True, null=True),
),
......

我唯一做的就是添加 - 将字段 periodic_task_interval 添加到 userproject 所以其他字段 - 为什么它们出现在迁移中?会不会因为数据库大而影响长时间的实际迁移?

最佳答案

如果您在字段中有 choices= 参数,您应该以“稳定的方式”(每次相同的顺序)生成它,例如使用 sorted()

TYPES = {
'DISTRICT': 'Округ',
'AREA': 'Район',
'STATION': 'Станция метро',
}
type = models.CharField(
max_length=255,
choices=sorted(TYPES.items()),
default='AREA',
)

关于python - 为什么 Django 迁移更改字段 (AlterField) 是没有被触及的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42542898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com