django - Wagtail(Django CMS)如何在wagtail中添加单个图像,简单的尝试以“OperationalError no such column:gallery_gallerysubpage.cover_id”结尾
问题描述
我的问题很简单,我只是不知道如何将单个图像添加为页面缩影。这是我的页面模型(我尝试了ImageChooserPanel 参考中所示):
class GallerySubpage(Page):
intro = models.CharField(max_length=250)
body = RichTextField(blank=True)
# THIS IS TAKEN FROM DOCS
cover = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
# This returns some dummy for a while. I want to replace this with some field that contain single Image
def main_image(self):
gallery_item = self.gallery_images.first()
if gallery_item:
return gallery_item.image
else:
return None
search_fields = Page.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
]
content_panels = Page.content_panels + [
FieldPanel('intro'),
FieldPanel('body', classname="full"),
InlinePanel('gallery_images', label = "Images that will be displayed on this page"),
# THIS IS TAKEN FROM DOCS
ImageChooserPanel('cover'),
]
当我运行代码时出现错误:
OperationalError at /gallery/galerry132/
no such column: gallery_gallerysubpage.cover_id
解决方案
如果您没有运行./manage.py makemigrations
并且./manage.py migrate
在添加cover
字段之后会发生上述错误。
推荐阅读
- apollo - apollo-server - 有条件地从选择集中排除字段
- postgresql - 我的 postgresql 容器 docker 上的远程控制工作但看不到表创建
- javascript - 忽略上下鼠标按下事件
- azure - 如何在 Azure Application Insight 仪表板中标记保留图
- c++ - OpenMP:共享同一算法的单线程和多线程实现
- php - PHP显示为空白
- css - 使用 css 选择器提取属性值
- logstash - ELK:通过日志存储读取 CSV 被延迟
- c++ - 具有多个变量的 if 语句
- python - 如何使用多个选择选项并选择这些选项以保持选中状态?