Django拒绝接受我的FloatField的一次性默认值

时间:2016-09-08 17:03:18

标签: python django

我有一个课程,我正在尝试为其添加新的FloatField。 Django想要一个默认值来填充现有的行(合理的)。但是,它拒绝接受我给它的任何价值。

You are trying to add a non-nullable field 'FIELDNAME' to CLASS without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
Select an option: -1
Please select a valid option: -1
Please select a valid option: -1
Please select a valid option: float(-1)
Please select a valid option: -1.0
Please select a valid option: float(-1.0)
Please select a valid option: 

我如何让它接受我的价值?

1 个答案:

答案 0 :(得分:7)

您应该选择选项1,然后输入您的值

 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
 1

选择1.它会要求提供您的默认值。

Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now()
>>> -1.0