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

  • 2020-05-12 02:49:54
  • OfStack

Once virtualenv and virtualenvwrapper are configured, create a new project using pycharm. After that, the problem comes. Previously, I directly used sqlite as the development database to learn. According to the principle of the previous tutorial, it seems that the development environment should be as close as possible to the production environment.

Ben thought it was something that should be easy, but he got into some trouble

According to 1 pass baidu, search out the program is probably:

MySQLdb
mysql comes with connector installed
pymysql

MySQLdb is the first database link library recommended by django, which is also the first one I tried. However, when installing, I could not find the installation file suitable for 64-bit python 2.78. Through the introduction of an article to modify the support for 2.7 version reluctantly installed, the results of the use of unicode always reported an error, mysql database is set to utf8 code according to the tutorial, had to give up

2. Built-in connector

Another version that looks very official, but the official installation method always indicates that there is no mysql.connector.django module... I don't know why. After careful searching, I found that those students who had successfully installed the software also reported an error in Chinese unicode. Remnants read aloud

3, pymysql

This is a blog post about the python3 trial django-mysql solution. 1 because unofficial did not make, but unexpectedly simple success...

Add in inti of project.py:


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, default is localhost
'PORT': '3306', # Database port, MySQL The default is 3306
'OPTIONS': {
'autocommit': True,
},
}
}


Related articles: