﻿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
25852	Batch migrations fail when dependent on a custom manager	lightstrike	Simon Charette	"Running a migration containing a `RunPython` operation that relies on a custom manager assigned using `migrations.alterModelManagers` in a previous migration within a batch migration sequences results in a `AttributeError` being thrown. Running the migration that assigns a new manager in a separate `manage.py migrate` command as the command that contains the `RunPython` operation succeeds as expected.

This issue was first raised in a [http://stackoverflow.com/questions/28788819/access-django-custom-user-manager-method-in-migration Stack Overflow post] in March. [http://stackoverflow.com/a/32365176/1118796 One of the answers] contains a workaround but this is less than ideal.

[https://github.com/charettes/django-ticketing/tree/master/ticket_geoff A sample app] was created that shows this bug in action. To reproduce:

1. Create new Django project & copy `ticket_geoff` app in root project directory.
2. Add `ticket_geoff` to `INSTALLED_APPS`
3. Run `python manage.py migrate` - note AssertionError
4. Run `python manage.py migrate` - this time it's okay

Another way to reproduce, showing that running the migration that changes model managers and running the migration with the `RunPython` command in separate migrate commands runs successfully:
1. Create new Django project & copy `ticket_geoff` app in root project directory.
2. Run `python manage.py migrate` - sets up base tables
3. Add `ticket_geoff` to `INSTALLED_APPS`
4. Run `python manage.py migrate ticket_geoff 0003` - all good
5. Run `python manage.py migrate ticket_geoff` - fine

''Special thanks to Django NYC for helping review this ticket''"	Bug	closed	Migrations	1.8	Normal	fixed		Simon Charette	Ready for checkin	1	0	0	0	0	0
