Django:尝试添加模型实例时出现服务器错误(500)

时间:2019-05-25 20:52:02

标签: django server model

当我继续localhost:8000/admin并单击“ Quotes + ADD”时,它向我显示错误500,而不是编辑界面。 “帖子”效果很好。我只是想知道,如果不看代码,您能否告诉我这个问题的不同来源? enter image description here

编辑:这是models.pyadmin.py

models.py

class TimestampedModel(models.Model):

    created = models.DateTimeField(auto_now_add = True)
    updated = models.DateTimeField(auto_now = True)

    class Meta:
        abstract = True


# Create your models here.
class Post(TimestampedModel):

    title = models.CharField(max_length = 255, default='')

    intro = models.TextField(default='')
    title_one = models.TextField(default='')
    text_one = models.TextField(default='')
    title_two = models.TextField(default='')
    text_two = models.TextField(default='')
    title_three = models.TextField(default='')
    text_three = models.TextField(default='')

    def __repr__(self):
        return self.title

class Quote(models.Model):
    quote = models.TextField(default='')
    author = models.CharField(max_length = 60, default='')

    def __repr__(self):
        return self.quote

admin.py

from django.contrib import admin
from .models import Post, Quote

# Register your models here.
admin.site.register(Post)
admin.site.register(Quote)

我还想告诉您,当我尝试进行迁移然后进行迁移时,它会显示“未检测到更改”。

ProgrammingError at /admin/blog/quote/

relation "blog_quote" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "blog_quote"

1 个答案:

答案 0 :(得分:1)

我猜可能是OperationalError,因为没有运行Quotes模型的迁移。

提供models.pyadmin.py的内容将使调试变得更加容易。