我有一個在數據庫中的現有模型。我想用hstore字段來增強它。我安裝hstore Postgres的擴展,Django的hstore應用,在Django項目改變了適當的設置:如何在添加hstore字段後創建遷移? (django-hstore與南)
SOUTH_DATABASE_ADAPTERS = {'default': 'south.db.postgresql_psycopg2'}
DATABASES = {
'default': {
'ENGINE': 'django_hstore.postgresql_psycopg2',
...
我檢查了Django應用程序的工作原理與新設置 - 它。所以我添加了新的字段到其中一個模型:
data = hstore.DictionaryField(db_index=True)
下一步:數據庫遷移。在這裏我迷路了。當試圖爲新字段創建遷移時,我得到:
The field 'Project.data' does not have a default specified, yet is NOT NULL.
Since you are adding this field, you MUST specify a default
value to use for existing rows. Would you like to:
1. Quit now, and add a default to the field in models.py
2. Specify a one-off value to use for existing columns now
我該怎麼做?我錯過了什麼?在任何django-hstore相關文章中,我沒有找到任何對默認值(或null = True)的引用。
呀,我試着用{}最初,這申請移民時破產。恐怕hstore.DictionaryField是一個完全不同的野獸。 – Mike 2013-04-09 18:41:28
問題可能是索引標誌,我認爲數據庫將字典作爲索引處理很複雜。 – PepperoniPizza 2013-04-09 19:55:46
實際上起初我沒有嘗試過,原來它是hstore DictionaryField的默認設置。 – Mike 2013-04-09 20:12:06