【发布时间】:2015-06-18 12:42:42
【问题描述】:
我有一个非常简单的场景
from django.test import TestCase
class BaseTest(TestCase):
fixtures = ('users.json',)
...
class SpecificTest(BaseTest):
fixtures = ('transactions.json',)
...
事务对用户有一个 FK,当 SpecificTest 尝试加载固定装置时,我得到一个 IntegrityError
IntegrityError: Problem installing fixtures:
The row in table 'app_transactions' with primary key '1' has an
invalid foreign key: app_transactions.user_id contains a value '30'
that does not have a corresponding value in app_user.id.
这个错误意味着BaseTest 中加载的users.json 固定装置没有在transactions.json 固定装置之前加载(如您所料)。我的问题是,子类化测试时加载夹具的正确方法是什么?
Django 1.7
【问题讨论】:
标签: django django-testing