﻿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
33677	Django test does not migrate parallel db's if --keepdb --parallel option is used	Barney Szabolcs	nobody	"To run my tests, I run
{{{
./manage.py test --keepdb --parallel -v 2
}}}
I use PostgreSQL 11 db on macOS Catalina 10.15.7 (19H2). 
The problem is that if I have any change in the db (eg. a field added), the parallel db's don't get migrated and thus the tests fail. 

The output when the tests fail after the migration:
{{{
Running migrations:
  Applying mymodel.0007_auto_20220503_1433... OK
Using existing clone for alias 'default' ('myproject_test')...
Cache table 'rhymedict_cache' already exists.
Using existing clone for alias 'default' ('myproject_test')...
Using existing clone for alias 'default' ('myproject_test')...
Using existing clone for alias 'default' ('myproject_test')...
...
======================================================================
ERROR: test_mytest
(myproject.myapp.test.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
...
psycopg2.errors.UndefinedColumn: column ""field2"" of relation ""myapp_mymodel"" does not exist
LINE 1: ... ""field1"", ""field2"") VA...
...
django.db.utils.ProgrammingError: column ""field2"" of relation ""myapp_mymodel"" does not exist
LINE 1: ... ""field1"", ""field2"") VA...
}}}

After I drop the myproject_test_1... myproject_test_4 db's manually and run the command again:

{{{
Using existing test database for alias 'default' ('myproject_test')...
Operations to perform:
  Synchronize unmigrated apps: analytical, compressor, cookielaw, corsheaders, crispy_forms, debug_toolbar, dj_rest_auth, django_hosts, genlocale, import_export, massadmin, menu, messages, rest_framework, rosetta, sitemaps, static_sitemaps, staticfiles
  Apply all migrations: myapp1, myapp2
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
Running migrations:
  No migrations to apply.
Cache table 'myproject_cache' already exists.
Using existing clone for alias 'default' ('myproject_test')...
Got an error creating the test database: source database ""myproject_test"" is being accessed by other users
DETAIL:  There is 1 other session using the database.
}}}

Without the --parallel option, the test command runs just fine.

My Django version is 2.2.12"	Bug	closed	Testing framework	2.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
