0
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 30
4, in handle
    app_output = self.handle_app(app, **options)
  File "D:\PythonPack\lib\site-packages\django\core\management\commands\sqlall.p
y", line 19, in handle_app
    return u'\n'.join(sql_all(app, self.style, connections[options.get('database
')])).encode('utf-8')
  File "D:\PythonPack\lib\site-packages\django\core\management\sql.py", line 145
, in sql_all
    return sql_create(app, style, connection) + sql_custom(app, style, connectio
n) + sql_indexes(app, style, connection)
  File "D:\PythonPack\lib\site-packages\django\core\management\sql.py", line 26,
 in sql_create
    tables = connection.introspection.table_names()
  File "D:\PythonPack\lib\site-packages\django\db\backends\__init__.py", line 89
5, in table_names
    cursor = self.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

このチュートリアルhttps://docs.djangoproject.com/en/dev/intro/tutorial01/に従っていますが、コマンドを実行しようとすると上記のエラーが発生します

python manage.py sql polls

何が問題なのか誰でも知っていますか? 本当にありがとうございました。

[更新] *強いテキスト*MANAGERS = ADMINS

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



INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'polls',
)
4

1 に答える 1

2

Sqlite3 には、データベース ファイルへのフル パスが必要です。データベース名が相対パスでないことを確認してください。

次のようになります。

import os
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite',
        'NAME': os.path.join(PROJECT_ROOT, 'dev.db'),
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

また、ファイルのパーミッションが厳しすぎないことも確認してください。

于 2012-06-24T13:36:45.570 に答える