0
製作博客的東西,數據庫等。事情是,我有一個名爲'posts'的數據庫。數據庫連接 - Django是自動重命名或者什麼的! CONFIGION
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'posts', # Or path to database file if using sqlite3.
'USER': '*******', # Not used with sqlite3.
'PASSWORD': '*******', # Not used with sqlite3.
'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '****', # Set to empty string for default. Not used with sqlite3.
}
models.py
from django.db import models
class posts(models.Model):
author = models.CharField(max_length = 30)
title = models.CharField(max_length = 100)
bodytext = models.TextField()
timestamp = models.DateTimeField()
views.py
from django.shortcuts import render_to_response
from models import posts
#from settings import default
def index(request):
entries = posts.objects.all()[:10]
return render_to_response('homepage/index.html', {'posts' : entries}
輸出
OperationalError at/
(1049, "Unknown database 'posts.homepage_posts'")
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4
Exception Type: OperationalError
Exception Value:
(1049, "Unknown database 'posts.homepage_posts'")
Exception Location: /Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg/MySQLdb/connections.py in __init__, line 187
Python Executable: /usr/bin/python
Python Version: 2.7.1
Python Path:
['/Users/thor/Sites/FirstBlog',
'/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
Server time: Wed, 2 May 2012 19:56:53 -0500
它會自動後綴.homepage_posts
的數據庫名稱,因此無法訪問我噸。請幫忙?
您是否完成了'./manage.py syncdb'並且成功了?另一個要嘗試的是直接查看錶('./manage.py dbshell',然後'SHOW TABLES')來查看發生了什麼。 – jozzas
我不認爲問題是它正在訪問'posts.homepage_posts' - 這是一個有效的database.table_name格式。 MySQL只是告訴你,由於數據庫不存在,帖子的一部分是無效的。所以是的,確保你已經運行'./manage.py syncdb'。 –