新手来了 我正在尝试使用 Django 创建一个博客。在我向帖子添加 slug 之前,一切正常/发布。但是,由于我添加了 slug,当我尝试在 /admin/blogengine/post/add/ 没有这样的列:blogengine_post.slug 中添加一个说 DatabaseError 的帖子时,我会收到错误消息。错误回溯是:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Django Version: 1.5.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'blogengine',
'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Template error:
In template /Users/chrissiepollock/projects/DjangoBlog/templates/posts.html, error at line 6
no such column: blogengine_post.slug
1 : <html>
2 : <head>
3 : <title>My Django Blog</title>
4 : </head>
5 : <body>
6 : {% for post in posts %}
7 : <h1><a href="/{{ post.slug }}">{{ post.title }}</a></h1>
8 : <h3>{{ post.pub_date }}</h3>
9 : {{ post.text }}
10 : {% endfor %}
11 : <br />
12 : {% if page.has_previous %}
13 : <a href="/{{ page.previous_page_number }}/">Previous Page</a>
14 : {% endif %}
15 : {% if page.has_next %}
16 : <a href="/{{ page.next_page_number }}/">Next Page</a>
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/chrissiepollock/projects/DjangoBlog/blogengine/views.py" in getPost
27. return render_to_response('posts.html', { 'posts':post})
File "/Library/Python/2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
29. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/Library/Python/2.7/site-packages/django/template/loader.py" in render_to_string
172. return t.render(Context(dictionary))
File "/Library/Python/2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/Library/Python/2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/Library/Python/2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/Library/Python/2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py" in render
148. len_values = len(values)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in __len__
90. self._result_cache = list(self.iterator())
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in iterator
301. for row in compiler.results_iter():
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
775. for rows in self.execute_sql(MULTI):
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
840. cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py" in execute
41. return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
366. six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
362. return Database.Cursor.execute(self, query, params)
Exception Type: DatabaseError at /admin
Exception Value: no such column: blogengine_post.slug
我跑了 manage.py sqlall myapp 并根据它,蛞蝓信息在那里(除非我读错了):
CREATE TABLE "blogengine_post" (
"id" integer NOT NULL PRIMARY KEY,
"title" varchar(200) NOT NULL,
"pub_date" datetime NOT NULL,
"text" text NOT NULL,
"slug" varchar(40) NOT NULL UNIQUE
) ;
几天来,我一直试图解决这个问题,逐行通读,从头开始并重新定位文件和文件夹,但没有任何效果。有任何想法吗?非常感谢您的帮助。