The database tables generated model class
Create a Django project
django-admin startproject ‘xxxx‘
Modify the setting file, set the database name and connection type you want to connect in setting inside, addresses and the like, and when you create a new project agreement
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sqlexam',
'USER': 'root',
'PASSWORD': 'root123456',
'HOST': '127.0.0.1',
'PORT': 3306
}
}
Then the corresponding models can be generated according to the model document database data
1, generate a model file
python3 manage.py inspectdb
2, will be introduced into the model file which app
Creating app
python3 manage.py startapp 'app名字'
The imported model created in the app
python3 manage.py inspectdb > app/models.py