- 在models.py中穿件BlogArticle
from django.db import models from django.utils import timezone from django.contrib.auth.models import User # Create your models here. class BlogArticle(models.Model): title = models.CharField(max_length=300) author = models.ForeignKey(User, related_name="blogs_posts",on_delete=models.CASCADE) body = models.TextField() publish = models.DateTimeField(default=timezone.now()) class Meta: ordering=("-publish",) def __str__(self): return self.title
命令行执行
python manage.py makemigrations **迁移** python manage.py sqlmigrate blog 0001 **更新到数据库** >python manage.py migrate **创建数据库**