Create a database
Create database haha default Charset=utf8;
Installing Pymysql
Pip Install Pymysql
The setting.py settings in the app are as follows
Import pymysqlpymysql.install_as_mysqldb () DATABASES = {' default ': {' ENGINE ': ' Django.db.backends.mysql ', ' NAME ' : ' MySite ', ' USER ': ' Root ', ' PASSWORD ': ' 123456 ', ' HOST ': ' 127.0.0.1 ', ' PORT ': ' 3306 ',}}
In C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\backends\mysql\ base.py to comment out the contents below
If version < (1, 3, 3): Raise Improperlyconfigured ("Mysqlclient 1.3.3 or newer is required; You have%s "% database.__version__)
Create a model
From django.db import Modelsclass Post (models. Model): title = models. Charfield (' title ', max_length=70) def __str__ (self): return Self.title
Migrating models
Python manage.py Makemigrationspython manage.py Migrate
python3.5 django2.0 using Pymysql to connect to MySQL