我正在尝试在我的django设置中连接mysql,然后尝试在命令行中运行django-admin db shell但它无法正常工作。 这是我的settings.py代码:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'investors_data',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
当我尝试运行django-admin dbshell时,我发现以下错误:
Traceback (most recent call last):
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Nishant Singh\AppData\Local\Programs\Python\Python36-32\Scripts\django-admin.exe\__main__.py", line 9, in <module>
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\base.py", line 322, in execute
saved_locale = translation.get_language()
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\utils\translation\__init__.py", line 195, in get_language
return _trans.get_language()
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\utils\translation\__init__.py", line 59, in __getattr__
if settings.USE_I18N:
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
self._setup(name)
File "c:\users\nishant singh\appdata\local\programs\python\python36-32\lib\site-packages\django\conf\__init__.py", line 39, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
尝试运行django-admin runserver
时出现类似错误答案 0 :(得分:0)
要在项目中执行任何操作,您应使用manage.py
而非django-admin.py
,因为它与特定设置文件相关联。