1. Create your own database manually
Create DATABASE name
2. Configure the database-related configuration in the Django project under the setting file
1DATABASES = {2 'default': {3 'ENGINE':'Django.db.backends.mysql',#Types of connection Databases4 'HOST':'127.0.0.1',#Connect to database address5 'PORT': 3306,#Port number6 'NAME':'Manage',#Database name7 'USER':'Kevin',#Database user name8 'PASSWORD':'12121',#Database Password9 }Ten}
3. Tell Diango to use Pymysql instead of MYSQLDB to connect to the database
Configure non-app _init_.py in the project's _init_.py file
1 Import Pymysql 2 # let Django use Pymysql instead of MYSQLDB. 3 pymysql.install_as_mysqldb ()
4. The model file in the app defines class (the Mapping database table name), and the class must inherit models. Model
The object of the class corresponds to a record of the table, and the attribute corresponds to a column record;
1 class UserInfo (models. Model):2 # self-increment type primary key 3 # not empty char length
5. Execute a command statement to create a data table
>>>python manage.py makemigrations
>>>python manage.py Migrate
Django-based ORM database configuration