1.创建app
python manage.py startapp xxx
在settings.py的INSTALLED_APP注册
2.创建pythonpackge(apps为例)
右击Mark Directory as->Sources Root
3.settings.py
import sys
sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
PS:2和3可简化为在INSTALLED_APP添加'apps.student'
4.创建数据库
在student.models.py
from django.db import models
# Create your models here.
class Student(models.Model):
gender_choices = (('男', '男'), ('女', '女'), ("保密", "保密"))
sno = models.CharField(db_column="SNO", primary_key=True, null=False,max_length=20)
name = models.CharField(db_column="name", max_length=20, null=False)
gender = models.CharField(db_column='gender', max_length=10, choices=gender_choices)
birthday = models.DateField(db_column="birthday",max_length=20)
mobile = models.CharField(db_column="mobile", max_length=11)
email = models.EmailField(db_column="email", max_length=50)
address = models.CharField(db_column="address", max_length=100)
image = models.CharField(db_column="image", max_length=200)
class Meta:
managed = True
db_table = "Student"
5.连接数据库
1)cmd
mysql -uroot -p
123456
2)创建数据库
create database db;
3)settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '100.114.116.36',
'PORT': '3306'
}
}
4)student/_init_.py
import pymysql
pymysql.install_as_MySQLdb()
5)将ORM转为数据库
python manage.py makemigrations
python manage.py migrate
标签:VUE,models,max,数据库,py,db,Django,column,length From: https://www.cnblogs.com/auslando/p/17235304.html