PyDev 和 Django:PyDev 破坏了 Django shell?

发布于 2024-08-31 02:31:03 字数 2227 浏览 2 评论 0原文

我已经建立了一个新项目,并用简单的模型填充它。 (基本上我正在遵循 tut

)我在命令行上运行 python manage.py shell ,它工作正常:

>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()
[]

效果很好。然后,我尝试在 Eclipse 中执行相同的操作(使用由相同文件组成的 Django 项目。)

右键单击我的网站项目>> 姜戈>>带有 Django 的外壳 环境

这是 PyDev 控制台的输出:

>>> 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

在这里做错了什么?

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 (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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初吻给了烟 2024-09-07 02:31:03

该错误与未打开数据库文件有关。所以我猜测 settings.py 中数据库的路径是相对路径,并且 PyDev 使用与通常使用的不同的当前目录启动 shell。

如果是这种情况,请将 DATABASE_NAME 设置更改为绝对路径,它应该可以工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文