﻿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
23694	"Swappable Dependency should not use ""__first__"""	no	nobody	"Along the same vein as the other bugs I've recently reported about changing a model's `db_table` option, it seems that changing it for `AUTH_USER_MODEL` breaks any henceforth migrations that will depend on it.

To reproduce, try something a long the following:
1. Start a new project and app with a customer `AUTH_USER_MODEL`, say `Employee`
2. Set the `db_table` of `Employee` to something, 'store_employee'
3. Create another model in another app

> djbug
>     djbug/settings.py -> AUTH_USER_MODEL = 'app.Employee'
>     /app1/models.py

{{{#!python
# /app1/models.py
class Employee(models.Model):
    class Meta:
        db_table = 'store_employee'

# /app2/models.py
class Store(models.Model):
    pass
}}}

4. Create and run migrations.
5. Change the `db_table` of `Employee` to the default, 'app_employee'.
6. Create an run the migrations with something like `migrations.AlterModelTable('Employee', 'accounts_employee')`
7. Add a many to many pointing to Employee
{{{#!python
# /app2/models.py
class Store(models.Model):
    employees = models.ManyTomanyField(settings.AUTH_USER_MODEL)
}}}
8. Create a new migration.

The migration generated will include the `migrations.swappable_dependency(settings.AUTH_USER_MODEL)` dependency, which expands to `('app1.Employee', '__first__')`. The problem with this, is that at `__first__`, the `db_table` option is pointing to a now non-existent table.

I propose that `migrations.swappable_dependency` instead use either `__latest__`, or find out what the current migration is for the application containing the `AUTH_USER_MODEL`."	Bug	closed	Migrations	1.7	Normal	wontfix		github@… Andrew Godwin Shai Berger	Unreviewed	0	0	0	0	0	0
