我有Ubuntu 12.10并且已经安装了Django。我正在尝试按照http://www.djangoproject.com上的教程进行操作。我正处于运行python manage.py syncdb
命令的位置。以下是追溯。
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 288, in _cursor
self._sqlite_create_connection()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 257, in _sqlite_create_connection
raise ImproperlyConfigured("Please fill out the database NAME in the settings module before using the database.")
django.core.exceptions.ImproperlyConfigured: Please fill out the database NAME in the settings module before using the database.
以下是我的settings.py文件的摘录:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', 'sqlite3'# Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
我做了很多Googling,并被告知对于NAME字段,要输入数据库文件的绝对路径。什么是数据库文件以及它位于何处?我知道我有sqlite3
。但是,我无法在任何地方找到任何.db
文件。我看到的另一个资源告诉我只需输入任何路径。当我这样做时,我收到Cannot open database
错误。非常感谢任何帮助。
答案 0 :(得分:3)
您需要为django提供创建数据库文件的位置 - 运行./manage.py syncdb
(您)的用户需要可写。
例如,您可以使用:
'NAME': '~/my_test_db.db',
在开发过程中,通常使用相对于settings.py
文件的位置:
from os import path
SETTINGS_ROOT = path.dirname(path.realpath(__file__)) # Folder where settings.py is
PROJECT_ROOT = path.normpath(path.join(SETTINGS_ROOT, '..')) # Django 1.4 project structure
...
'NAME': path.join(PROJECT_ROOT, 'project.db'),
在旁注中,您的设置文件中似乎有拼写错误:
'ENGINE': 'django.db.backends.sqlite3', 'sqlite3'
应为:
'ENGINE': 'django.db.backends.sqlite3','
答案 1 :(得分:-3)
提高ImproperlyConfigured(“需要SQLite 3.8.3或更高版本(已找到%s)。”%Database.sqlite_version) django.core.exceptions.ImproperlyConfigured:需要SQLite 3.8.3或更高版本(发现3.7.17)。