鹡鸰 - 运行测试提高 psycopg2。完整性错误:列 "draft_title" 中的空值违反了非空约束



我正在尝试运行我的应用程序测试(Django v1.11 和 Wagtail v2.2.1(,但在测试创建测试数据库时出现异常:

Traceback (most recent call last): File "/home/fleon/.virtualenvs/virmyasb/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) psycopg2.IntegrityError: null value in column "draft_title" violates not-null constraint DETAIL: Failing row contains (3, 0001, 1, 1, Root, root, t, f, /, , f, , null, null, f, 1, null, f, null, null, null, null, null).

查看完整堆栈跟踪时,Wagtail 文件中存在错误:

[...] lib/python3.6/site-packages/wagtail/core/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py", line 30, in initial_data [...]

这一行中的 Python 代码是:

# Create root page
root = Page.objects.create(
title="Root",
slug='root',
content_type=page_content_type,
path='0001',
depth=1,
numchild=1,
url_path='/',
) 

它没有设置draft_title,因此违反了非空约束。

请注意,我正在使用两个不同的数据库(base.py(:

DATABASES = {
'default': dj_database_url.config(),
'thedbname': {
'NAME': 'thedbname',
'ENGINE': 'django.db.backends.mysql',
'USER': 'thedbuser',
'PASSWORD': '***',
'HOST': 'myhost',
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
},
}
}

如果我删除 MySQL 数据库(?

迁移wagtail/core/migrations/0040_page_draft_title.py中将Page.draft_title字段添加到鹡鸰中。由于迁移始终适用于迁移时存在的模型的冻结版本,因此0001_squashed_0016_change_page_url_path_to_text_field.py中的代码是有效的 -draft_title当时不存在。

该错误表明由于某种原因,迁移发生了正常顺序 - 我建议检查项目中的迁移是否存在任何依赖项行,例如可能影响顺序的run_before- 或者在已经应用迁移的数据库上重新运行(但没有将它们记录在django_migrations表中, 所以 Django 不知道这一点(。

最新更新