【问题标题】:Why I get an operational error even I migrate为什么即使我迁移也会出现操作错误
【发布时间】:2021-09-20 00:33:55
【问题描述】:

我正在用 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

【问题讨论】:

  • 请用准确的错误跟踪更新问题...

标签: python django django-models


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2014-04-01
    • 2020-12-15
    • 2015-09-22
    相关资源
    最近更新 更多