2012-02-02 144 views
1

由於某種原因,我得到一個DatabaseError "no such column: myapp_customer.redirect_link_id"。在另一臺計算機上與我具有完全相同的代碼的人沒有此問題。我們使用Django南遷移,並根據它我完全瞭解最新的型號:DatabaseError「no such column」

$ python manage.py schemamigration myapp --auto 
Nothing seems to have changed. 

$ python manage.py migrate myapp 
Running migrations for myapp: 
- Nothing to migrate. 
- Loading initial data for myapp. 
No fixtures found. 

這裏是一個完整的堆棧跟蹤:

Traceback: 
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response 
    111.       response = callback(request, *callback_args, **callback_kwargs) 
File "/Users/me/sources/django_myapp/../django_myapp/myapp/views.py" in main_page 
    66.   customer = Customer.objects.select_related().get(user = request.user) 
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in get 
    344.   num = len(clone) 
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in __len__ 
    82.     self._result_cache = list(self.iterator()) 
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in iterator 
    273.   for row in compiler.results_iter(): 
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in results_iter 
    680.   for rows in self.execute_sql(MULTI): 
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql 
    735.   cursor.execute(sql, params) 
File "/Library/Python/2.7/site-packages/django/db/backends/util.py" in execute 
    34.    return self.cursor.execute(sql, params) 
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute 
    234.    return Database.Cursor.execute(self, query, params) 

Exception Type: DatabaseError at/
Exception Value: no such column: myapp_customer.redirect_link_id 

我跑manage.py sqlall myapp,並根據它, redirect_link_id存在於數據庫中:

CREATE TABLE "myapp_customer" (
    "id" integer NOT NULL PRIMARY KEY, 
    "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id"), 
    "client_key" varchar(9) NOT NULL UNIQUE, 
    "api_key" varchar(30) NOT NULL UNIQUE, 
    "redirect_link_id" integer REFERENCES "myapp_full_link" ("id"), 
    "message_title" varchar(200), 
    "message_body" text, 
    "customer_group_id" integer NOT NULL REFERENCES "myapp_customer_group" ("id") 
) 
; 
+0

'myapp_full_link'表已存在且具有完整性? – 2012-02-02 08:37:20

+3

sqlall不會顯示數據庫的當前狀態。它顯示了從頭開始設置數據庫所需的SQL。使用dbshel​​l命令,然後'.schema'(對於SQLite) – Alasdair 2012-02-02 09:38:40

+0

因此,根據sqllite,myapp_customer表實際上沒有'redirect_link_id'列。 myapp_full_link確實存在問題:爲什麼南遷移沒有根據我的模型創建列? – babonk 2012-02-02 20:03:07

回答

0

您確定您還擁有myapp/migrations目錄中最新的遷移文件嗎?

+0

我很確定。我再次檢查了工作機器,並且沒有任何未跟蹤的遷移。 – babonk 2012-02-02 06:43:09

+0

''./manage.py migrate --list''也可能給出一些關於遷移狀態的指針。除此之外,我建議檢查數據庫級別的實際當前模式,並將其當前狀態與south_migrationhistory表中的遷移記錄進行比較,以查看錯誤發生的位置。 – Raekkeri 2012-02-02 06:53:25

+0

工作機器和非工作機器具有與該命令相同的輸出。另外,請參閱上文,我運行了manage.py sqlall,它似乎意味着我有實際的分區 – babonk 2012-02-02 07:00:33

相關問題