0

我在创建默认 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.

有什么想法吗?

4

1 回答 1

0

更仔细地阅读文档。NAME 应该并且必须是绝对路径。采取了文档部分 2.3.1

NAME – 您的数据库的名称。如果您使用 SQLite,数据库将是您计算机上的一个文件;在这种情况下,NAME 应该是该文件的完整绝对路径,包括文件名。如果该文件不存在,当您第一次同步数据库时会自动创建它(见下文)。

指定路径时,请始终使用正斜杠,即使在 Windows 上也是如此(例如 C:/homes/user/mysite/sqlite3.db)。

于 2012-12-18T06:39:28.667 回答