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)