gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 02:09:03 24 4
gpt4 key购买 nike

我有一个类,我正在尝试向它添加一个新的 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,然后输入您的值

 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

关于python - Django 拒绝接受我对 FloatField 的一次性默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39396610/

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