简体   繁体   English

MySQL无法与Python 3.6和Django 1.9一起使用

[英]Mysql not working with python 3.6 and django 1.9

I am trying to connect mysql db with django 1.9 and python version is 3.6. 我正在尝试使用django 1.9连接mysql db,而python版本是3.6。 With database connection string I am getting the below error. 使用数据库连接字符串时,出现以下错误。 If I comment out the database connection string the site is loading fine. 如果我注释掉数据库连接字符串,则说明该站点加载良好。 Can anybody tell what is wrong in this. 谁能告诉我这是什么问题。

[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

My pip freeze 我的点冻结

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

DB Settings we are using to try to connect to the Mysql 我们用来尝试连接到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',
        },
    }
}

Usually, this error means there is an error in the Django project somewhere. 通常,此错误表示Django项目中某处存在错误。 It could be hard to locate. 可能很难找到。

You can try multiple solutions like: 1. Restart Apache 2. Execute makemigrations and migrate Django commands 3. Modify your wsgi.py file so you can manage the exception 您可以尝试多种解决方案,例如:1.重新启动Apache 2.执行makemigrations并迁移Django命令3.修改wsgi.py文件,以便您可以管理异常

A little note, in the line File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py" indicate that you're using Python 3.6 and not Python 3.5 as you mentioned in your description. File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py"行中的一点说明表明您使用的是Python 3.6,而不是您在Python 3.5中提到的您的描述。

Python 3.6 is officially supported until Django 1.11, so you maybe must upgrade your Django version or downgrade your Python in your venv. 直到Django 1.11为止,Python 3.6才正式受支持,因此您可能必须升级Django版本或在venv中降级Python。

Related posts: - Post 1 - Post 2 - Post 3 - Post 4 - Post 5 相关职位:- 职位1- 职位2- 职位3- 职位4- 职位5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM