由于某种原因,我得到一个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")
)
;
'myapp_full_link'表已存在且具有完整性? – 2012-02-02 08:37:20
sqlall不会显示数据库的当前状态。它显示了从头开始设置数据库所需的SQL。使用dbshell命令,然后'.schema'(对于SQLite) – Alasdair 2012-02-02 09:38:40
因此,根据sqllite,myapp_customer表实际上没有'redirect_link_id'列。 myapp_full_link确实存在问题:为什么南迁移没有根据我的模型创建列? – babonk 2012-02-02 20:03:07