目前我已经为Django在/Users/hobbes3/Sites/
中创建了两个符号链接。一个ls -l
显示以下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/
其中mysite/
是我唯一的Django项目(从官方投票教程建)。
当我键入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 2012-02-24 22:41:09
进入目录/ mysite之后,运行没有参数的python manage.py inspectdb。 – 2012-02-24 22:47:12
哦,我刚刚意识到你说过在'mysite'里面使用'manage.py'而不是'django-admin.py'。谢谢,现在为我工作。现在我只需要临时创建一个新项目来读取'doors-eer'数据库,然后运行'inspectdb'。 – hobbes3 2012-02-24 22:49:13