0

我想用 Django ORM 调用数据库。我有这个问题:

  *@*:~/standAlone$ python manage.py sql MyApp
    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/home/*/django/core/management/__init__.py", line 443, in execute_fr                                                                                        om_command_line
        utility.execute()
      File "/home/*/django/core/management/__init__.py", line 382, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/home/*/django/core/management/__init__.py", line 261, in fetch_comm                                                                                        and
        klass = load_command_class(app_name, subcommand)
      File "/home/*/django/core/management/__init__.py", line 69, in load_comman                                                                                        d_class
        module = import_module('%s.management.commands.%s' % (app_name, name))
      File "/home/*/django/utils/importlib.py", line 35, in import_module
        __import__(name)
      File "/home/*/django/core/management/commands/sql.py", line 4, in <module>
        from django.core.management.sql import sql_create
      File "/home/*/django/core/management/sql.py", line 6, in <module>
        from django.db import models
      File "/home/*/django/db/__init__.py", line 11, in <module>
        if DEFAULT_DB_ALIAS not in settings.DATABASES:
      File "/home/*/django/utils/functional.py", line 184, in inner
        self._setup()
      File "/home/*/django/conf/__init__.py", line 42, in _setup
        self._wrapped = Settings(settings_module)
      File "/home/*/django/conf/__init__.py", line 95, in __init__
        raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s"                                                                                         % (self.SETTINGS_MODULE, e))
    ImportError: Could not import settings '{{ project_name }}.settings' (Is it on s   
4

1 回答 1

0

这是{{ project_name }}.settings您复制/粘贴代码方式的产物吗?还是{{ project_name }}真的在您的 manage.py 文件中?这将解释错误。可能是使用某些工具生成项目后遗留下来的?

或者,您的 django 设置环境变量设置为 (django < 1.4) 是什么。或者,你的 manage.py 中的相应os.environ['...']设置是什么(如果你使用 django 1.4)?

于 2012-04-25T20:05:53.067 回答