﻿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
31308	Fixture loading fails when more than one Test case uses same fixtures	Lokesh Gurram	nobody	"If I have more than one TestCase using the same fixture, loading data between test cases raises unique constraint violation error on Postgres (works fine on SQLite)

{{{
class Test1(TestCase):
    fixtures = ['fixture.json']

    def test_demo(self):
        u = User.objects.get(username='testuser1')
        #some testing

class Test2(TestCase):
    fixtures = ['fixture.json']

    def test_demo2(self):
        #some testing
        pass
}}}

**where my fixture.json is**
Profile table has a one-to-one relation with User table.
{{{
[
{
    ""model"": ""app1.user"",
    ""pk"": 1,
    ""fields"": {
        ""password"": """",
        ""last_login"": null,
        ""is_superuser"": false,
        ""username"": ""testuser1"",
        ""first_name"": """",
        ""last_name"": """",
        ""is_staff"": false,
        ""is_active"": true,
        ""date_joined"": ""2020-02-21T12:59:17.302Z"",
        ""email"": null,
        ""groups"": [],
        ""user_permissions"": []
    }
},
{
    ""model"": ""app1.profile"",
    ""pk"": 1,
    ""fields"": {
        ""user"": 1,
        ""firebaseID"": null,
        ""phone"": null,
        ""completed_till"": 0,
    }
}
]

}}}

Running each Test Case separately works fine. But when we run them in one go, first Test case goes through and before the second test case executes, I get this error - 

{{{
django.db.utils.IntegrityError: Problem installing fixture 'C:\...\app1\fixtures\fixture.json': Could not load app1.Profile(pk=1): duplicate key value violates unique constraint ""app1_profile_user_id_key""
}}}


Any idea why the DB is not completely cleared before trying to load the fixtures for the next TestCase. I tested this with Django 2.2 on Postgres 10/12.  The problem persists in both. 
Interestingly though testing on SQLite doesn't give any problem."	Bug	closed	Testing framework	2.2	Normal	invalid	Testcases, fixtures		Unreviewed	0	0	0	0	0	0
