关注python Anywhere教程时出错

时间:2014-11-24 03:30:27

标签: python syncdb

我正在尝试在任何地方的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 $ 

1 个答案:

答案 0 :(得分:0)

有一些事情可能会导致此问题:

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

    而不是~/project/mydata.db使用/home/user/project/mydata.db

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

    sudo python manage.py syncdb

    如果可行,则需要解决一个简单的权限错误。

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

    项目名称:test

    数据库名称test.db