現在、私は/Users/hobbes3/Sites/
にDjangoの2つのシンボリックリンクを作成しました。 ls -l
はmysite/
は(公式投票のチュートリアルから構築された)私の唯一のDjangoプロジェクトで、次のDjango:django-admin.pyでのインポートエラー
lrwxr-xr-x 1 hobbes3 staff 66B Feb 23 04:16 django -> /usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/
lrwxr-xr-x 1 hobbes3 staff 85B Feb 23 01:01 django-admin.py -> /usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/bin/django-admin.py
drwxr-xr-x 15 hobbes3 staff 510B Feb 24 16:04 mysite/
を示しています。
私はpython django-admin.py
を入力すると、すべてが正常
[email protected]:~/Sites$ python django-admin.py
Usage: django-admin.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=all output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Print traceback on exception
--version show program's version number and exit
-h, --help show this help message and exit
Type 'django-admin.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
cleanup
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
reset
runfcgi
runserver
shell
sql
sqlall
sqlclear
sqlcustom
sqlflush
sqlindexes
sqlinitialdata
sqlreset
sqlsequencereset
startapp
startproject
syncdb
test
testserver
validate
に動作します。しかし、私はinspectdb
コマンドを使用しようとすると、私はインポートエラー
[email protected]:~/Sites$ python django-admin.py inspectdb doors-eer
Traceback (most recent call last):
File "django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/core/management/commands/inspectdb.py", line 5, in <module>
from django.db import connections, DEFAULT_DB_ALIAS
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/db/__init__.py", line 14, in <module>
if not settings.DATABASES:
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
を取得し、私はうまくプロジェクトを開始することができますことに気づきましたpython django-admin.py startproject asd
となります。
私はPython 2.7.2とDjango 1.3.1を実行しています。
私は 'cd mysite'を実行し、' python ../django-admin.py inspectdb door-eer'を実行しても、同じエラーが表示されます。 'settings.py'を開き、' DATABASE'変数が正しく設定されていることを確認しました... – hobbes3
/mysiteディレクトリに移動した後、引数なしでpython manage.py inspectdbを実行します。 –
ああ、ちょうど 'django-admin.py'の代わりに' mysite'の中で 'manage.py'を使うと言ったことに気付きました。ありがとうございました。今度は 'doors-eer'データベースを読み込み、' inspectdb'を実行するために新しいプロジェクトを一時的に作成するだけです。 – hobbes3