I am trying to sync the database on the tutorial of python anywhere. I have deleted all the contents and restarted the tutorial several times, when I do:
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 $
There are a few things that could cause this issue:
If you are using a relative path to the sqlite file in your settings.py try changing it to an absolute path:
Instead of
~/project/mydata.db
use/home/user/project/mydata.db
.If you don't have your permissions set up correctly you could have an issue writing to a file. Try this:
sudo python manage.py syncdb
If that works, it's a simple permission error you need to resolve.
There could be a name conflict between your project's directory filename and your database file. If your database name in settings.py is the same as your project name, try adding a
.db
to your file name:I.E.
project name:
test
database name
test.db