【问题标题】:Error when following the python anywhere tutorial遵循 python 随处教程时出错
【发布时间】:2014-11-24 03:30:27
【问题描述】:

我正在尝试在任何地方同步 python 教程上的数据库。我已经删除了所有内容并重新启动了几次教程,当我这样做时:

python ./manage.py syncdb

03:23 ~ $ cd mysite
03:23 ~/mysite $ ls
__init__.py __init__.pyc manage.py media settings.py settings.pyc static testdb urls.py urls.pyc
03:23 ~/mysite $ python ./manage.py syncdb
Traceback (most recent call last):
File "./manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, 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 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 56, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 250, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 207, in _cursor
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file
03:24 ~/mysite $ 

【问题讨论】:

    标签: python syncdb


    【解决方案1】:

    有几件事可能会导致此问题:

    1. 如果您在 settings.py 中使用 sqlite 文件的相对路径,请尝试将其更改为绝对路径:

      /home/user/project/mydata.db代替~/project/mydata.db

    2. 如果您的权限设置不正确,您可能会在写入文件时遇到问题。试试这个:

      sudo python manage.py syncdb

      如果可行,这是您需要解决的简单权限错误。

    3. 项目的目录文件名和数据库文件之间可能存在名称冲突。如果 settings.py 中的数据库名称与项目名称相同,请尝试在文件名中添加.db

      I.E.

      项目名称:test

      数据库名称test.db

    【讨论】:

      猜你喜欢
      • 2020-04-05
      • 2012-09-24
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2018-08-14
      • 2014-12-17
      • 2023-03-17
      相关资源
      最近更新 更多