﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9207	Failing test code when using contenttypes app.	Oliver Andrich	nobody	"In a project where I use the django.contrib.contenttypes app, I see errors in almost all my tests involving contenttypes. The error message below is from mysql, but I can also reproduce it for postgresql. sqlite3 seems to be save.

{{{
IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails 
(`test_test_content_type_sync_auth_bug/auth_permission`, CONSTRAINT `content_type_id_refs_id_728de91f` 
FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`))')
}}}


Seems as some created foreign key constraints aren't satisfied.

For reproduction I created a minimal django project (see the attached zip file). If you run ""./manage.py test testapp"" inside this project, you will see the error message.

I have tracked down this issue to the call to the flush command in the _pre_setup method of the django.test.TestCase class. Further tracking inside this method showed, that everything works fine until the django.contrib.auth apps post_syncdb signal handlers are called. The strange part about that is, that ""./manager.py flush --verbosity=0 --noinput"" basically does the same and doesn't cause such problems.

The model in the testapp application has a ForeignKey relationship to the ContentType model as described in http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/. The User model itself has no reverse generic relation is provided, as this is impossible for me with the User model. 

I hope this information helps to track that issue, and I also hope I haven't missed anything."	Bug	closed	contrib.contenttypes	1.0	Normal	fixed		oliver.andrich@… aball@…	Accepted	0	0	0	0	0	0
