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 linesimport pymysqlpymysql.install_as_MySQLdb()settings.py# vim ./mysite/settings.pyDATABASES = {'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 = dbnameuser = dbuserpassword = passworddefault-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!