﻿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
24351	RunPython/RunSQL operations in contrib migrations and multi-db routers.	Loic Bistuer	nobody	"By default the `RunPython` and `RunSQL` don't give much information to the multi-db router, and before #22583 the router wasn't even consulted.

In Django 1.7 multi-db users could avoid issues by not using those operations and avoiding any 3rd party app that uses them. But in Django 1.8 the `contenttypes` application adds a `RunPython` operation that will fail in many multi-db setups ([https://github.com/django/django/blob/b4ac23290772e0c11379eb2dfb81c750b7052b66/django/contrib/contenttypes/migrations/0002_remove_content_type_name.py#L33-L36 see commit]).

To fix the immediate issue we can leverage the feature added by #22583 and provide hints to the router:

`RunPython(foo, bar, hints={'app_label': 'contenttypes'})`

and/or

`RunPython(foo, bar, hints={'affected_models': [ContentType]})`

Another option would be to make `allowed_to_migrate` always provide `allow_migrate` with the `app_label` for the current migration.

Both options would be backwards incompatible in the same way (although the first one is constrained to people that use `django.contrib.contenttypes`) because they require routers to accept the `app_label` kwarg or the new `**hints` syntax ([https://github.com/django/django/blob/8f4877c89d0f28e289399fbb46357623a49e7eb0/docs/releases/1.8.txt#L465-L469 see release notes]).

Note that #22583 already introduced a backward incompatibility ([https://github.com/django/django/blob/8f4877c89d0f28e289399fbb46357623a49e7eb0/docs/releases/1.8.txt#L1038-L1044 see release notes]) so people already have to update their existing routers for 1.8.

The advantage of the second option is that it'll automatically work for `RunPython` and `RunSQL` operations from 3rd party apps.
"	New feature	closed	Migrations	1.8alpha1	Normal	fixed			Ready for checkin	1	0	0	0	0	0
