我正在尝试将 mysql db 与 django 1.9 连接,python 版本是 3.6。使用数据库连接字符串我收到以下错误。如果我注释掉数据库连接字符串,则该网站加载正常。谁能告诉我这有什么问题吗?
[Wed Apr 05 07:01:08.287609 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] mod_wsgi (pid=29791): Target WSGI script '/home/abhadran/test/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Apr 05 07:01:08.287675 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] mod_wsgi (pid=29791): Exception occurred processing WSGI script '/home/abhadran/test/mysite/mysite/wsgi.py'.
[Wed Apr 05 07:01:08.287705 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] Traceback (most recent call last):
[Wed Apr 05 07:01:08.287740 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/test/mysite/mysite/wsgi.py", line 20, in <module>
[Wed Apr 05 07:01:08.287787 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] application = get_wsgi_application()
[Wed Apr 05 07:01:08.287798 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/myenv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Wed Apr 05 07:01:08.290733 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] django.setup(set_prefix=False)
[Wed Apr 05 07:01:08.290756 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/myenv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
[Wed Apr 05 07:01:08.290779 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] apps.populate(settings.INSTALLED_APPS)
[Wed Apr 05 07:01:08.290790 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py", line 78, in populate
[Wed Apr 05 07:01:08.291738 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] raise RuntimeError("populate() isn't reentrant")
[Wed Apr 05 07:01:08.291768 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] RuntimeError: populate() isn't reentrant
我的点卡住了
Django==1.9.12
django-tastypie==0.13.3
mod-wsgi==4.5.15
mysql-connector-python==2.0.4
mysqlclient==1.3.10
PyMySQL==0.6
python-dateutil==2.6.0
python-mimeparse==1.6.0
requests==2.13.0
six==1.10.0
我们用来尝试连接到 Mysql 的数据库设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'AAAAAAAAAAAAAAAAA',
'NAME': 'ZZZZZZZZZZZZZZZZ',
'USER': 'YYYYYYYYYYYYYYYY',
'PASSWORD': 'XXXXXXXXXXXX',
'PORT': '3306',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
},
}
}
最佳答案
通常,这个错误意味着Django项目中的某个地方有错误。可能很难找到。
您可以尝试多种解决方案,例如: 1. 重新启动 Apache 2.执行makemigrations并迁移Django命令 3.修改您的wsgi.py文件以便您可以管理异常
请注意,在 File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py"
行中表明您正在使用正如您在描述中提到的那样,Python 3.6 而不是 Python 3.5。
Python 3.6 在 Django 1.11 之前得到正式支持,因此您可能必须升级 Django 版本或在 venv 中降级 Python。
关于python - Mysql 不适用于 python 3.6 和 django 1.9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43224200/