【问题标题】:Generating tables for INSTALLED_APPS fails为 INSTALLED_APPS 生成表失败
【发布时间】:2012-06-13 18:12:07
【问题描述】:
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "D:\PythonPack\lib\site-packages\django\core\management\__init__.py", lin
e 443, in execute_from_command_line
    utility.execute()
  File "D:\PythonPack\lib\site-packages\django\core\management\__init__.py", lin
e 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\PythonPack\lib\site-packages\django\core\management\base.py", line 19
6, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "D:\PythonPack\lib\site-packages\django\core\management\base.py", line 23
2, in execute
    output = self.handle(*args, **options)
  File "D:\PythonPack\lib\site-packages\django\core\management\base.py", line 37
1, in handle
    return self.handle_noargs(**options)
  File "D:\PythonPack\lib\site-packages\django\core\management\commands\syncdb.p
y", line 57, in handle_noargs
    cursor = connection.cursor()
  File "D:\PythonPack\lib\site-packages\django\db\backends\__init__.py", line 30
6, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "D:\PythonPack\lib\site-packages\django\db\backends\sqlite3\base.py", lin
e 281, in _cursor
    self._sqlite_create_connection()
  File "D:\PythonPack\lib\site-packages\django\db\backends\sqlite3\base.py", lin
e 271, in _sqlite_create_connection
    self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file

我在尝试后遇到了这些错误

python manage.py syncbd

在本教程中 https://docs.djangoproject.com/en/dev/intro/tutorial01/

使用 Django 启动第一个 Web 应用程序(Dian-go 或 Jan-go ?)。 有人可以帮助我导致这些错误消息的原因吗?

更新

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'D:\Python\mysite\sqlitedb',                      # 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.
    }
}

那是数据库设置

【问题讨论】:

  • 您是否正确配置了数据库设置?看来您正在使用 SQLite3,但是当您运行该命令时它确实会创建一个数据库文件吗?
  • 我更新澄清。它根本不创建任何 db 文件,而是显示上述错误
  • 创建一个database file first
  • Django 应该能够自己创建数据库文件。 Django真的可以写在你希望数据库文件所在的目录吗?

标签: python django django-models django-admin django-views


【解决方案1】:

Windows 用户应在 settings.py 中使用 / 而不是 \ 作为文件路径。
使用D:/Python/mysite/sqlitedb 而不是D:\Python\mysite\sqlitedb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    相关资源
    最近更新 更多