【问题标题】:can't makemigrations in wagtail不能在鹡鸰中迁移
【发布时间】:2021-06-30 15:05:53
【问题描述】:

我正在尝试迁移此模型,但收到此错误消息。

您正在尝试在没有默认值的情况下向 secondsection 添加不可为空的字段“id”;

我正在使用 wagtail 2.11.3 和python 3.6

我想生成以下内容:

在 CMS 中为页面添加标题

说明

三个部分

第一部分将有:

1-文字

2-图像

3- 标题

第二部分将有:

1- 一个标题

2- 三个带有标题副标题和文字的块

第三部分将有:

1- 标题

2-文本

3-图像

我见过这个solution,它不起作用



from django.db import models
from wagtail.core.fields import *
from wagtail.admin.edit_handlers import *
from wagtail.images.edit_handlers import *
from modelcluster.fields import ParentalKey
from wagtail.core.models import Orderable


class AboutUs(Page):
    """About us Model"""
    templates = 'aboutus/about_us.html'
    description = models.TextField(blank=True, null=True)
    banner_image = models.ForeignKey(
        "wagtailimages.Image",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )
    first_section_title = models.CharField(max_length=100, blank=True, null=True)
    first_section_text = models.TextField(max_length=100, blank=True, null=True)
    first_section_image = models.ForeignKey(
        "wagtailimages.Image",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )

    second_section_title = models.CharField(max_length=100, blank=True, null=True)

    third_section_title = models.CharField(max_length=100, blank=True, null=True)
    third_section_Text = models.TextField(blank=True, null=True)
    third_section_image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )

    content_panels = Page.content_panels + [
        MultiFieldPanel(
            [
                FieldPanel('description'),
                ImageChooserPanel('banner_image')
            ],
            heading='Banner Section'
        ),
        MultiFieldPanel([
            FieldPanel('first_section_title'),
            FieldPanel('first_section_text'),
            ImageChooserPanel('first_section_image'),
        ],
            heading='First section'),
        MultiFieldPanel(
            [
                FieldPanel('second_section_title'),
                InlinePanel("second_section", max_num=3, min_num=1, label='Second Section'),

            ],
            heading='Second Section'
        ),
        MultiFieldPanel([
            FieldPanel('third_section_title'),
            FieldPanel('third_section_Text'),
            ImageChooserPanel('third_section_image')
        ],
            heading='Third section')

    ]

    class SecondSection(Orderable):
        """about us second section"""

        second_section_subtitle = models.CharField(max_length=100, blank=False, null=True, default="", editable=True)
        second_section_Text = models.TextField(blank=False, null=True, default="", editable=True)
        page = ParentalKey("aboutus.AboutUs", related_name="second_section")




编辑:我删除了迁移文件,之后,我能够进行迁移,但出现了另一个问题,当我尝试保存表单时收到一条消息

aboutus_aboutus 表没有名为 second_section_title 的列

【问题讨论】:

    标签: python django wagtail


    【解决方案1】:

    删除数据库然后进行迁移,然后迁移解决了问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多