1.在models.py文件内创建表格并设置外键等属性,执行python3 manage.py makemigrations和python3 manage.py migrate 生成表格
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class Student(models.Model):
"""学生表"""
name = models.CharField(max_length=100,default='')
gender = models.SmallIntegerField(default=0)
class Meta:
db_table = 'student'
class Course(models.Model):
"""课程表"""
name = models.CharField(max_length=100,default='')
teacher = models.ForeignKey("Teacher",on_delete=models.SET_NULL,null=True,default='')
class Meta:
db_table = 'course'
class Score(models.Model):
"""分数表"""
student = models.ForeignKey("Student",on_delete=models.CASCADE,default='')