﻿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
32495	Migrations that modify constraints raise an exception on multi-schema databases	Chris Spencer	nobody	"I have a multi-tenant Django application with a PostgreSQL backend that separates user data using uniquely named schemas. Each tenant has a separate front-end website and settings file, specifying their unique database connection parameters. The schema structures are identical and are managed and migrated the same way.

I'm finding this setup is not fully supported by Django, in that I'm unable to migrate any changes to indexes or constraints.

The query that retrieves the old SQL object to update (django.db.backends.postgresql.introspection.DatabaseIntrospection.get_constraints) retrieves any object matching the name. The problem is that it's able to see across any schema the current user has access to, and not just the current schema being migrated, resulting in an error like:

    ValueError: Found wrong number (7) of constraints for myapp_mytable(col1, col2, col3)

i.e. This error would be thrown if I had 7 schemas on a database, all containing the same constraint, and I tried to migrate one of the schemas.

I've been able to work around this issue by monkey patching the get_constraints method using a variation of my submitted patch (https://github.com/django/django/pull/14067), which just updates the query to filter by the current schema.
"	Bug	closed	Migrations	3.1	Normal	duplicate			Unreviewed	0	0	0	0	0	0
