1.命令行创建django文件
进入指定目录
django-admin startproject item
cd item
python manage.py startapp item0
2.编写sql语句
setting
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'item0',
]
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME':'practice',
'USER':'root',
'PASSWORD':'',
'HOST':'127.0.0.1',
'PORT':'3306',
}
}
init.py admin.py 同级文件
import pymysql
pymysql.install_as_MySQLdb()
models.py
from django.db import models
# Create your models here.
class Book(models.Model):
name = models.CharField(max_length=20)
price = models.IntegerField()
pub_date = models.DateField()
运行命令
python manage.py makemigrations
python manage.py migrate