开发者

PyDev and Django: PyDev breaking Django shell?

I've set up a new project, and populated it with simple models. (Essentially I'm following the tut.)

When I run python manage.py shell on the command line, it works fine:

>python manage.py shell

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (In开发者_Python百科tel)] 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 thing in Eclipse (using a Django project that is composed 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?


The error is about not being open the database file. So I'd guess that the path to the database in your settings.py is a relative path, and PyDev starts the shell with a different current directory than you normally use.

If this is the case, change the DATABASE_NAME setting to an absolute path and it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜