简体   繁体   中英

can't makemigrations in wagtail

I'm trying to migrate this model, and I get this error message.

You are trying to add a non-nullable field 'id' to secondsection without a default;

I'm using wagtail 2.11.3 and python 3.6

I want to generate the following:

in CMS to add a title for the page

description

and three sections

the first section will have:

1- text

2- image

3- title

the second section will have:

1- a title

2- three blocks with title subtitle and text

the third section will have:

1- title

2-text

3-image

I've seen this solution , it didn't work



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")




Edit: I deleted the migrations files and after that, I was able to make the migrations but another problem appeared, when trying to save the form I get a message

table aboutus_aboutus has no column named second_section_title

deleting the database and then making migrations and after that migrate solved the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM