我在创建默认的sqlite3数据库时遇到问题,我不确定原因:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydatabase', # 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.
}
}
这是我尝试使用syncdb
时收到的错误Traceback (most recent call last):
File "C:\Users\name\eclipseProjects\mysite\mysite\manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 371, in handle
return self.handle_noargs(**options)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "C:\Python27\lib\site-packages\django\db\backends\dummy\base.py", line 15, in complain
raise ImproperlyConfigured("You haven't set the database ENGINE setting yet.")
django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet.
有什么想法吗?
答案 0 :(得分:0)
仔细阅读文档。 NAME应该而且必须是绝对路径。采用文档部分2.3.1
NAME - 数据库的名称。如果您正在使用SQLite,那么数据库 将是您计算机上的文件;在这种情况下,NAME应该是完整的 该文件的绝对路径,包括文件名。如果文件没有 存在,它将在您同步时自动创建 数据库第一次(见下文)。
指定路径时,始终使用正斜杠,即使在Windows上也是如此 (例如C:/homes/user/mysite/sqlite3.db)。