Django connection mysql stepped pit

1. Create a database

2, settings.py configuration database files in a Django project

3, the Django project __init__.py file, instead of using pymysql MySqlDB

import pymysql
pymysql.install_as_MySQLdb()

4, in the packet app models.py file, using ORM

class UserInfo(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20, null=False)

Note: You must be inherited modles.Model

5, the table generation

python manage.py makemigrantions

Pit 1

Solution:

"D:\Python\Lib\site-packages\django\db\backends\mysql\base.py"

Base.py open files, comments

Pit 2, continues to run the command

Solution

"D:\Python\Lib\site-packages\django\db\backends\mysql\operations.py"

Open the file operations.py

6, run the command

python manage.py migrate

7, pay attention

Change: app name + table name (table name to lower case)

 

Guess you like

Origin www.cnblogs.com/wt7018/p/11221666.html