Django models generated using database tables based reverse

The models generated based Django reverse existing database table

A. Create a Django project

django-admin startproject ‘xxxx‘

Second, modify the settings file

Set the name of the database you want to connect in setting inside, address, account and password information and the like, and when you create a new project agreement

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'djangodemo',	# 数据库名称
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': 3306
    }
}

Generating a corresponding database data models in accordance with model class

Generation model file

python3 manage.py inspectdb

The model file to import them app

Creating app

python3 manage.py startapp 'app名字'

The imported model created in the app

python3 manage.py inspectdb > app/models.py

Guess you like

Origin www.cnblogs.com/zhangchaocoming/p/12563461.html