#2631: pysqlite2.dbapi2.OperationalError: no such table - SQLite needs full path
for settings.DATABASE_NAME
------------------------------+---------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Type: defect | Status: new
Priority: lowest | Milestone:
Component: Database wrapper | Version:
Severity: trivial | Keywords:
------------------------------+---------------------------------------------
If the sqlite database is given a relative path in settings.DATABASE_NAME
( e.g. "database.db" ), then any trying to load it from a subdir fails at
first database access as pysqlite can't find the table (i.e. it's assuming
we're creating the database).
e.g.:
{{{
project/databasename.db/
project/somedir/
project/somedir/script.py
}}}
script.py looks like:
{{{
#!/usr/bin/env python
import sys,os
# Django bootstrap from http://fnordia.org/?q=node/483
project_dir = os.path.abspath('../')
project_name = os.path.basename(project_dir)
sys.path.append(os.path.join(project_dir, '..'))
sys.path.append("..")
sys.path.pop()
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project_name
from django.conf import settings
from wnmm.monkeys.models import Play
P = Play.objects.get(pk=1)
}}}
and does this:
{{{
minerva:~/wnmm/data simon$ python script.py
Traceback (most recent call last):
File "script.py", line 16, in ?
P = Play.objects.get(pk=1)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/models/manager.py", line 67, in get
return self.get_query_set().get(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/models/query.py", line 211, in get
obj_list = list(clone)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/models/query.py", line 103, in __iter__
return iter(self._get_data())
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/models/query.py", line 430, in _get_data
self._result_cache = list(self.iterator())
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/models/query.py", line 172, in iterator
cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") +
",".join(select) + sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/backends/util.py", line 12, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/django/db/backends/sqlite3/base.py", line 79, in execute
return Database.Cursor.execute(self, query, params)
pysqlite2.dbapi2.OperationalError: no such table: monkeys_play
}}}
Fixing this is probably outside the scope of Django as the user should
really use the fullpath to the database, but I'm posting it here in case
anyone else is having the same problem.
Possible ways of fixing - get the SQLite database wrapper to translate
the relative path to the fullpath.
You can easily work around it by doing this in your settings:
{{{
from os.path import realpath
DATABASE_NAME = realpath('database.db')
}}}
...or in your script, before you import any of your models:
{{{
project_dir = os.path.abspath('../') # or path to the dir. that the db
should be in.
settings.DATABASE_NAME = os.path.join( project_dir, settings.DATABASE_NAME
)
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/2631>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---