gpt4 book ai didi

python-3.x - 鹡鸰:Locale_ID 不能为空

转载 作者:行者123 更新时间:2023-12-05 01:32:48 24 4
gpt4 key购买 nike

我正在尝试在 pythonanywhere 上部署一个带有 wagtail 2.11 的网站。但是,我无法在前端保存任何页面模型。

原因似乎是在我的“主页”-app 中,无法应用迁移 0002_create_homepage.py。尝试这样做会给我这个错误(IntegrityError: (1048, "Column 'locale_id' cannot be null")):

File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/migrations/migration.py", line 121, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards
self.code(from_state.apps, schema_editor)
File "/home/yogagarten/yogagarten.pythonanywhere.com/home/migrations/0002_create_homepage.py", line 21, in create_homepage
homepage = HomePage.objects.create(
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/query.py", line 447, in create
obj.save(force_insert=True, using=self.db)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/base.py", line 753, in save
self.save_base(using=using, force_insert=force_insert,
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/base.py", line 789, in save_base
parent_inserted = self._save_parents(cls, using, update_fields)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/base.py", line 818, in _save_parents
updated = self._save_table(
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/base.py", line 895, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/base.py", line 933, in _do_insert
return manager._insert(
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/query.py", line 1254, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1397, in execute_sq
l
cursor.execute(sql, params)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wra
ppers
return executor(sql, params, many, context)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/yogagarten/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 78, in execute
raise IntegrityError(*tuple(e.args))
django.db.utils.IntegrityError: (1048, "Column 'locale_id' cannot be null")

我的设置.py

INSTALLED_APPS = [
'wagtail.locales',
]

LANGUAGE_CODE = 'de-DE'
LANGUAGES = [('de', 'German'),]
WAGTAILADMIN_PERMITTED_LANGUAGES = [('de', 'German'),]
TIME_ZONE = 'Europe/Berlin'

USE_I18N = True
USE_L10N = True
USE_TZ = True

基本模型示例:

class HomePage(Page):
template = 'home/index.html'
ueberschrift = models.CharField(max_length=60, blank=False, null=True)
content_panels = ([FieldPanel('ueberschrift')])

class Meta:
verbose_name = 'Startseite'

我还没有创建任何页面对象。

你能给我一些关于如何修复这个错误的建议吗?我知道每个页面模型都带有一个语言环境字段。但我不知道如何处理这些信息。

我尝试过的:

  • 用新的数据库重做了一切
  • 将语言设置重置为默认值(en-us)
  • 我尝试了 run_before命令。
  • 我检查了这个answer并关注了这一部分官方documentation

我在 django 3.1.3 和 python 3.8 中使用 wagtail 2.11。

非常感谢!

最佳答案

您需要将以下行添加到 0002_create_homepage.py 迁移文件中,在 class Migration 中:

run_before = [
('wagtailcore', '0053_locale_model'),
]

由于 Wagtail 2.11 中新的多语言实现,此更改是必要的。更多详情在这里:https://docs.wagtail.io/en/stable/releases/2.11.html#run-before-declaration-needed-in-initial-homepage-migration

如果您已经运行 ./manage.py migrate 而没有此新行并收到 locale_id IntegrityError,您将需要删除并重新创建数据库,然后重新运行 ./manage.py migrate,因为之前的失败将使数据库处于不一致状态。 (删除并重新创建数据库将删除所有现有数据,但由于此问题只会出现在干净数据库上的新部署中,所以这应该不是问题。)

关于python-3.x - 鹡鸰:Locale_ID 不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65369636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com