为什么即使我迁移也会出现操作错误

时间:2021-07-09 16:50:11

标签: python django django-models

我正在用 django 建立一个博客,我尝试向模型添加新字段。我还进行了迁移并迁移到数据库。我还尝试了许多其他类似的东西 stackoverflow,stackoverflow question 2但我终于在/没有这样的列处出现操作错误:

from django.db import models
from django.contrib.auth.models import User
from ckeditor.fields import RichTextField
STATUS = (
(0,"Draft"),
(1,"Publish")
)
class Post(models.Model):
title = models.CharField(max_length=200, unique=True)
slug = models.SlugField(max_length=200, unique=True)
author = models.ForeignKey(User, on_delete=
models.CASCADE,related_name='blog_posts')
updated_on = models.DateTimeField(auto_now= True)
content = RichTextField(blank=True, null=True)
created_on = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(choices=STATUS, default=0)
image = models.ImageField(upload_to='images',null=True, blank=True)
class Meta:
ordering = ['-created_on']
def __str__(self):
return self.title

1 个答案:

答案 0 :(得分:1)

我知道一种解决此错误的方法,首先您必须删除数据库,然后在 python manage.py makemigrations 之后运行此命令 python manage.py migrate --run-syncdb 运行此命令。希望它有效。

相关问题