数据库错误“没有这样的列”
由于某种原因,我收到DatabaseError“没有这样的列:myapp_customer.redirect_link_id”
。在另一台计算机上具有与我完全相同的代码的人不会出现此问题。我们使用 Django-South 进行迁移,根据它,我完全了解该模型:
$ 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")
)
;
for some reason I'm getting a DatabaseError "no such column: myapp_customer.redirect_link_id"
. Someone who has the same exact code as me on another computer doesn't have this issue. We use Django-South for migration and according to it i'm completely up to date with the model:
$ 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.
Here's a full stack trace:
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
I ran manage.py sqlall myapp
and according to it, the redirect_link_id is present in the db:
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")
)
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定您还拥有 myapp/migrations 目录中的最新迁移文件吗?
Are you sure you also have the most recent migration files from myapp/migrations directory?