﻿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
31208	Index introspection fails on Postgresql in presence of schema copy	Shai Berger	Shai Berger	"Take a normal database schema created by Django.

Duplicate it under a different schema name (e.g. `pg_dump` it into a file, `ALTER SCHEMA public RENAME TO other`, and then `psql` the dump file).

Following this operation, index introspection fails -- if you look for an index for a column, it will not be found, because the introspection queries now return the columns lists doubled.

In details: For a Postgresql connection `conn`, the function `conn.introspection.get_constraints()`  returns a dictionary whose keys are the constraint and index names and whose values are themselves dictionaries of information for constraints and indexes. In the situation described above, the `'columns'` entry in these dictionaries has the contents `['column_name', 'column_name']` where it should have just `['column_name']`. When Django code later looks for indexes for the specified columns, it compares this entry to `['column_name']`, and since they are not equal, the index will not be found.

Context:

We sometimes like to take database contents from one machine and recreate the database on another.

In cases where the target database cluster already had some contents, we like to preserve it first by renaming the schema. We usually delete the renamed schema once the new schema creation completes successfully, but someone forgot it and our code which relied on the introspection erred (the schemas in our case were not exact duplicates, but similar enough).

Found this on 1.11, but the relevant code is the same on master:
"	Bug	closed	Database layer (models, ORM)	dev	Normal	invalid			Unreviewed	0	0	0	0	0	0
