所以我正在尝试将SearchVectorField添加到 Django 中的模型中:
class JobPosting(models.Model):
...
...
search_vector = SearchVectorField()
Run Code Online (Sandbox Code Playgroud)
我知道它应该是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 …Run Code Online (Sandbox Code Playgroud)