[英]django.db.utils.OperationalError: no such table: auth_user
[英]django.db.utils.OperationalError: foreign key mismatch - "project_projectpage" referencing "auth_user"
这个问题首先想说什么?
下面是我的model.py
class ProjectPage(Page):
"""
A Project Page
We access the People object with an inline panel that references the
ParentalKey's related_name in ProjectPeopleRelationship. More docs:
http://docs.wagtail.io/en/latest/topics/pages.html#inline-models
"""
introduction = models.TextField(
help_text='Text to describe the page',
blank=True)
image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
)
body = StreamField(
BaseStreamBlock(), verbose_name="Page body", blank=True
)
subtitle = models.CharField(blank=True, max_length=255)
tags = ClusterTaggableManager(through=ProjectPageTag, blank=True)
date_published = models.DateField(
"Date article published", blank=True, null=True
)
#email = models.CharField(max_length=255, blank=True, null=True)
email = models.ForeignKey(User, on_delete=models.PROTECT, to_field='email', null=True)
content_panels = Page.content_panels + [
FieldPanel('subtitle', classname="full"),
FieldPanel('introduction', classname="full"),
ImageChooserPanel('image'),
StreamFieldPanel('body'),
FieldPanel('date_published'),
InlinePanel(
'project_person_relationship', label="Author(s)",
panels=None, min_num=1),
FieldPanel('email'),
FieldPanel('tags'),
FieldPanel('added_by', classname="full"),
FieldPanel('updated_by', classname="full"),
]
search_fields = Page.search_fields + [
index.SearchField('body'),
]
added_by = models.ForeignKey(People,related_name="project_added_by", null=True, blank=True, on_delete=models.SET_NULL)
updated_by = models.ForeignKey(People,related_name="project_updated_by", null=True, blank=True, on_delete=models.SET_NULL)
created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)
updated_at = models.DateTimeField(auto_now=True, null=True, blank=True)
以上问题的解决方案是什么,如果您想了解这个问题的更多细节,请告诉我!!!!
我不知道,但我认为这里有电子邮件 ID 或其他地方的问题,因为我在此之后添加了电子邮件 ID,可能会出现此问题。
Django 的User
模型上的email
声明是:
email = models.EmailField(_('email address'), blank=True)
Django 文档的这一部分说,如果您链接到默认键之外的任何字段(例如您尝试链接到email
),则必须使用unique=True
声明该字段,但email
不是'吨。 您尝试链接方式的问题在于User
模型的email
字段上没有索引,因为它没有声明为唯一的。
像这样链接到 Django 用户模型会更标准(默认情况下,链接是在用户模型的默认键,id 上建立的):
from django.contrib.auth import get_user_model
user = models.ForeignKey(get_user_model(), on_delete=models.PROTECT, null=True)
使用上述声明,在您的模板中,您将通过{{ page.user.email }}
获得链接用户的电子邮件,但我想知道将用户链接到页面的架构。 请记住,Wagtail 有一个权限结构,您可以使用它为特定页面类型/模型的用户组分配权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.