不能在鹡鸰中迁移
can't makemigrations in wagtail
我正在尝试迁移此模型,但收到此错误消息。
You are trying to add a non-nullable field 'id' to secondsection without a default;
我正在使用 wagtail 2.11.3
和 python 3.6
我想生成以下内容:
在 CMS 中为页面添加标题
描述
和三个部分
第一部分将有:
1- 文字
2- 图片
3-标题
第二部分将有:
1-一个标题
2- 标题副标题和正文三块
第三部分将有:
1- 标题
2-文本
3 张图片
我看过这个,没用
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")
编辑:我删除了迁移文件,之后,我能够进行迁移,但出现了另一个问题,在尝试保存表单时我收到一条消息
table aboutus_aboutus has no column named second_section_title
删除数据库然后进行迁移,然后迁移解决了问题
我正在尝试迁移此模型,但收到此错误消息。
You are trying to add a non-nullable field 'id' to secondsection without a default;
我正在使用 wagtail 2.11.3 和 python 3.6
我想生成以下内容:
在 CMS 中为页面添加标题
描述
和三个部分
第一部分将有:
1- 文字
2- 图片
3-标题
第二部分将有:
1-一个标题
2- 标题副标题和正文三块
第三部分将有:
1- 标题
2-文本
3 张图片
我看过这个
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")
编辑:我删除了迁移文件,之后,我能够进行迁移,但出现了另一个问题,在尝试保存表单时我收到一条消息
table aboutus_aboutus has no column named second_section_title
删除数据库然后进行迁移,然后迁移解决了问题