所以我想一個SearchVectorField添加到模型在Django:在Django
class JobPosting(models.Model):
...
...
search_vector = SearchVectorField()
我得到它的值應爲nullable
或有一個默認值,以便能夠遷移,所以我刪除了表中的所有條目以防止此問題。
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
當我收到以下錯誤?我不想讓列可以爲空,如果我可以避免它,我寧願沒有默認值。
我的問題是,有沒有辦法強制makemigrations
和migrate
,因爲我不明白問題,如果表是空的。我有其他表中的數據,我不想刪除,所以不能刪除數據庫中的所有信息。
或者,如果選項1)
是解決方案,我將如何格式化此類型的字段的默認值?我認爲這不是一個正常的文本字段?
感謝您的任何幫助。