【发布时间】:2017-09-01 18:15:19
【问题描述】:
所以我正在尝试将SearchVectorField 添加到 Django 中的模型:
class JobPosting(models.Model):
...
...
search_vector = SearchVectorField()
我知道它应该是 nullable 或具有能够迁移的默认值,因此我删除了表中的所有条目以防止出现此问题。
但是,我在运行 makemigrations 时遇到以下错误:
You are trying to add a non-`nullable` field 'search_vector' to jobposting 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:
如果表是空的,为什么会这样说?我不想使列可以为空,如果可以避免,我宁愿没有默认值。
我的问题是,有没有办法强制makemigrations 和migrate,因为如果表是空的,我不明白这个问题。我有其他表,其中包含我不想删除的数据,因此无法删除数据库中的所有信息。
或者,如果选项1) 是解决方案,我将如何格式化此类字段的默认值?我认为这不是一个普通的文本字段?
感谢您的帮助。
【问题讨论】:
标签: python django postgresql django-models django-postgresql