0
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和migrations。这会在表中添加 title_en,但不会在前面呈现博客。在添加之前django-modeltranslation,博客正在正确呈现,没有任何错误。

4

1 回答 1

0

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

因此,如果您要迁移现有数据,那么makemigrationsmigrate还应该运行update_translation_fields它将任何现有值复制到空的默认语言列中。

您可以多次运行此操作(稍后将翻译添加到其他模型时),它仅在_en字段为空时复制值。

于 2018-09-15T13:05:31.823 回答