Django1.7+python 2.78+pycharm configure the mysql database tutorial

  • 2020-04-02 14:22:07
  • OfStack

Once virtualenv and virtualenvwrapper are configured, create a new project using pycharm. The problem comes later. I have been using sqlite as the development database to learn. According to the principles of the previous tutorial, it seems that the development environment should be as consistent as possible with the production environment.

Ben thought it should be a very easy thing, did not expect to encounter some trouble

According to a baidu, search out the program is probably:

MySQLdb
The connector that comes with the mysql installation
pymysql

MySQLdb
Django recommended the first database link library recommended by django, which was naturally the first one I tried. But you can't find a file to install 64-bit python2.78! Through an article about the modification reluctantly installed support version 2.7, the result is always used when unicode error, mysql database is set to utf8 encoding as the tutorial said, had to give up

2. Built-in connector

Another official looking version, but the official installation method always prompts that there is no mysql.connector.django module... I don't know why. After careful searching, I found that those students who successfully installed the system encountered an error in Chinese unicode. Remnants read aloud

3, pymysql

This is the blog's solution for trying out django-mysql in python3. At first because unofficial did not make, but unexpectedly simple success...

Add in inti.py of project:


import pymysql
pymysql.install_as_MySQLdb()
settings: DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Database engine
'NAME': 'django', # The database name
'USER': 'user', # The user name
'PASSWORD': 'password!', # password
'HOST': 'localhost', # Database host, by default localhost
'PORT': '3306', # Database port, MySQL The default is 3306
'OPTIONS': {
'autocommit': True,
},
}
}


Related articles: