PyDev and Django: Does PyDev break the Django wrapper?

I created a new project and filled it with simple models. (Essentially, I'm following tut .)

When I run python manage.py shell

on the command line, it works great:

>python manage.py shell

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from mysite.myapp.models import School
>>> School.objects.all()
[]

      

Works great. Then I try to do the same in Eclipse (using a Django project consisting of the same files.)

Right click on mysite project -> Django -> Shell with Django environment

This is the output from the PyDev console:

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python26\python.exe 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
>>> 
>>> from django.core import management;import mysite.settings as settings;management.setup_environ(settings)
'path\\to\\mysite'
>>> from mysite.myapp.models import School
>>> School.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 68, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 83, in __len__
    self._result_cache.extend(list(self._iter))
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 238, in iterator
    for row in self.query.results_iter():
  File "C:\Python26\lib\site-packages\django\db\models\sql\query.py", line 287, in results_iter
    for rows in self.execute_sql(MULTI):
  File "C:\Python26\lib\site-packages\django\db\models\sql\query.py", line 2368, in execute_sql
    cursor = self.connection.cursor()
  File "C:\Python26\lib\site-packages\django\db\backends\__init__.py", line 81, in cursor
    cursor = self._cursor()
  File "C:\Python26\lib\site-packages\django\db\backends\sqlite3\base.py", line 170, in _cursor
    self.connection = Database.connect(**kwargs)
OperationalError: unable to open database file

      

What am I doing wrong here?

+2


a source to share


1 answer


The error is that the database file cannot be opened. So I am assuming that the database path in your settings.py file is a relative path and PyDev starts up the shell with a different current directory than you usually use.



If so, change the parameter DATABASE_NAME

to an absolute path and it should work.

+3


a source







All Articles