Django with Mariadb
Take reference from:
http://blog.csdn.net/wmj2004/article/details/53215944
As described in django documentation, mysql is supported by build in models, but in ./manage.py shell
:
>>> from django.db import backends
There is no backends.mysql
, and ./manage.py
would pop errore: Error loading MySQLdb module: No module named MySQLdb
, the official document doesn’t work well.
Here is how to deal with this error:
# pip install pymysql
Then modify __init__.py
in mysite:
# vim ./mysite/__init__.py
# add followed lines
import pymysql
pymysql.install_as_MySQLdb()
settings.py
# vim ./mysite/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': './mysite/my.cnf',
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", }
}
}
# the last line is to activate strict mode of mysql, can be read at:
https://docs.djangoproject.com/en/1.11/ref/databases/
Modify my.cnf
# vim ./mysite/my.cnf
[client]
database = dbname
user = dbuser
password = password
default-character-set = utf8
Make sure dbuser has proper authority.
After all above, django site would run properly.
Comments (0)
Leave a Comment
No comments yet. Be the first to comment!