gpt4 book ai didi

python-3.x - django 模型在每次迁移时都会收到 Alter Field 警报

转载 作者:行者123 更新时间:2023-12-02 02:35:26 25 4
gpt4 key购买 nike

每次运行命令 python manage.py makemigrations 时,我都会收到 alter filed 警报 我还删除了我的数据库旧迁移文件,但警报仍然存在 谁知道我该如何解决这个问题问题?

Migrations for 'assignment':
assignment/migrations/0012_auto_20201016_0754.py
- Alter field city on assignment
- Alter field status on assignment
class Assignment(models.Model):

CITY_SELECT = {
('i', 'Islamabad'),
('l', 'Lahore'),
('m', 'Multan'),
('k', 'Karachi'),
('q', 'Queta'),
('p', 'Pashawar')
}

STATUS_SELECT = {
('p', 'Pendding'),
('d', 'Done'),
('i', 'In field'),
('c', 'Cancel')
}

place = models.CharField(max_length=100)
desc = models.CharField(max_length=500)
reporter = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
created_on = models.DateTimeField(auto_now_add=True)
assign_time = models.DateTimeField(auto_now=False, null=True)
city = models.CharField(choices=CITY_SELECT, max_length=9)
status = models.CharField(choices=STATUS_SELECT, max_length=8)

最佳答案

很可能该集合每次都以不同的顺序“打乱”,使得选择不可预测。如果多次运行 Python 进程,每次的哈希常数都不一样。您可以使用列表,这将确保顺序始终相同:

class Assignment(models.Model):

CITY_SELECT = <b>[</b> # ← use a list
('i', 'Islamabad'),
('l', 'Lahore'),
('m', 'Multan'),
('k', 'Karachi'),
('q', 'Queta'),
('p', 'Pashawar')
<b>]</b>

STATUS_SELECT = <b>[</b> # ← use a list
('p', 'Pendding'),
('d', 'Done'),
('i', 'In field'),
('c', 'Cancel')
<b>]</b>

place = models.CharField(max_length=100)
desc = models.CharField(max_length=500)
reporter = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
created_on = models.DateTimeField(auto_now_add=True)
assign_time = models.DateTimeField(auto_now=False, null=True)
city = models.CharField(choices=CITY_SELECT, max_length=9)
status = models.CharField(choices=STATUS_SELECT, max_length=8)

关于python-3.x - django 模型在每次迁移时都会收到 Alter Field 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64396098/

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