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

2024-04-26 14:07:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个类,正在尝试向它添加一个新的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: 

如何让它接受我的价值?


Tags: todjangoyouadddefaultfloatselectare
1条回答
网友
1楼 · 发布于 2024-04-26 14:07:17

您应该选择选项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 

相关问题 更多 >