Django'title_en'不在列表中

问题描述 投票:0回答:1
Request Method: GET
Request URL:    http://localhost:8000/blog/blog-title/
Django Version: 1.10.8
Exception Type: ValueError
Exception Value:    
'title_en' is not in list
Exception Location: /lib/python3.6/site-packages/django/db/models/query.py in __init__, line 1715
Python Executable:  /bin/python
Python Version: 3.6.5

安装django-modeltranslation后我在我的django网站上收到此错误。我试过在translationOptions中添加字段。还试过makemigration和迁移。这会在表格中添加title_en,但它不会在前面呈现博客。在添加django-modeltranslation之前,博客正在正确呈现而没有任何错误。

django python-3.x django-templates mezzanine django-modeltranslation
1个回答
0
投票

model-translation添加到已包含数据的现有模型时,数据仍存储在原始列(例如title)中,但不会复制到新的默认语言列title_en

因此,如果您要迁移现有数据,请在makemigrationsmigrate之后运行update_translation_fields,它会将任何现有值复制到空的默认语言列中。

您可以多次运行(稍后向其他模型添加转换时),它仅在_en字段为空时复制值。

© www.soinside.com 2019 - 2024. All rights reserved.