TestCase swallows IntegrityError when creating object with invalid foreign key
Django's TestCase class seems to swallow
IntegrityErrors when creating and saving an object when a foreign key is manually specified that is invalid.
save() in this case, no exception is raised, and the object returned by
save() is given a valid
id. However, the object is not actually saved to the database. When switching from
TransactionTestCase, the error is raised as expected when saving, and the error looks something like the following:
IntegrityError: insert or update on table "app_table1" violates foreign key constraint "app_table1_table2_id_fkey"
DETAIL: Key (table2_id)=(X) is not present in table "app_table2".
Change History (8)
Database layer (models, ORM) →