[英]Synthetic/redundant Django migrations caused by sysdate dependent date validator
I have a date field like the one below in a Django model, where I want the date to be in the future (or today, but not in the past). 我在Django模型中有一个类似于下面的日期字段,我希望该日期是将来的日期(或今天,而不是过去的日期)。
foo = models.DateField('Foo', null=True,
validators=[MinValueValidator(date.today())])
This works fine, validation happens as expected on forms, however, makemigrations
creates a new migration every day it runs with that date, below is an example produced today: 这可以正常工作,可以按预期在表单上进行验证,但是,
makemigrations
在该日期运行的每一天makemigrations
创建一个新的迁移,以下是今天产生的示例:
field=models.DateField(null=True,
validators=[django.core.validators.MinValueValidator(
datetime.date(2018, 1, 26))]
How can I avoid this? 如何避免这种情况? Should I use a custom validator instead of
MinValueValidator
or add a clean
method to the Form
subclass instead like this ? 我应该使用一个自定义的验证,而不是
MinValueValidator
或添加一个clean
方法将Form
的子类,而不是像这样 ?
There's no way to avoid this. 无法避免这种情况。 You've got a couple of options.
您有两种选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.