小编JR *_*uez的帖子

改变了 Django 模型。我为 DateField 提供了一次性默认值 = datetime.date。发现无效。删除了字段,仍然无法迁移

嗨,这是我在 models.py 中添加的特定行

billingMonth2 = models.DateTimeField()

这就是 makemigrations 中发生的事情,我想我添加了一个不可为空的字段,所以我尝试定义一个默认值:

    You are trying to add a non-nullable field 'billingMonth' to bills 
    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)
    2) Quit, and let me add a default in models.py
    Select an option: 1
    Please enter the default value now, as valid Python
    The datetime and django.utils.timezone modules …
Run Code Online (Sandbox Code Playgroud)

python linux django datetime models

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

datetime ×1

django ×1

linux ×1

models ×1

python ×1