2014-05-01 24 views
0

我有一個用戶模型的自定義用戶配置文件的django數據庫。 問題是,當我想向我的userprofile類添加新字段時,在嘗試訪問users表時,出現有關新字段的錯誤no such columnDjango 1.6與現有用戶編輯userprofile模型

任何方式來更新userprofile模型,而不必重建數據庫?

謝謝。

回答

1

這裏是如何做到這一點..

首先安裝south

pip install south 

然後添加到您的設置INSTALLED_APP名單爲 - ?

..., 
    'south', 
    ... 

什麼是南..那麼南是一款django應用程序,可幫助您更新數據庫而無需重新構建它。

python manage.py schemamigration <appname> --auto 
python manage.py migrate <appname> 

你可以在這裏找到完整的文檔 - - 現在,每當你更新你的模型只需要與執行更新時間初始化你的模型與 -

python manage.py syncdb // this will create the south tables for migrations 
python manage.py schemamigration <appname> --initial // (once per app) this will create the initial model files in a migrations package 
python manage.py migrate 

然後http://south.readthedocs.org/en/latest/tutorial/

+0

謝謝您回答Mahmud,我已經嘗試過,但是即使這樣做,我仍然得到'沒有這樣的列'錯誤,並且即使我重做數據庫,我也得到同樣的錯誤。我想我錯過了那裏的東西:( – Alqueraf

+0

你能顯示導致錯誤的代碼或模型嗎? –

+0

好的,發現問題。看起來我不能用現有的字段做到這一點。 首先,我必須刪除它們(或者修改它們,這樣南方將刪除並添加新的),然後用新字段運行遷移。 用舊字段遷移不起作用:) – Alqueraf