From 31eac71a760b5f30796abfb0b18c3f7578b93e84 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 8 May 2014 21:48:10 -0700 Subject: [PATCH] [1.7.x] Tests for #22325 --- tests/migrations/test_executor.py | 22 +++++++++++++ .../0001_initial.py | 31 +++++++++++++++++++ .../test_migrations_custom_user/__init__.py | 0 3 files changed, 53 insertions(+) create mode 100644 tests/migrations/test_migrations_custom_user/0001_initial.py create mode 100644 tests/migrations/test_migrations_custom_user/__init__.py diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py index e8dcacd80e..be3909d719 100644 --- a/tests/migrations/test_executor.py +++ b/tests/migrations/test_executor.py @@ -167,3 +167,25 @@ class ExecutorTests(MigrationTestBase): executor.migrate([("migrations", None)]) self.assertTableNotExists("migrations_author") self.assertTableNotExists("migrations_tribble") + + @override_settings( + MIGRATION_MODULES={"migrations": "migrations.test_migrations_custom_user"}, + AUTH_USER_MODEL="migrations.Author", + ) + def test_custom_user(self): + """ + Regression test for #22325 - references to a custom user model defined in the + same app are not resolved correctly. + """ + executor = MigrationExecutor(connection) + self.assertTableNotExists("migrations_author") + self.assertTableNotExists("migrations_tribble") + # Migrate forwards + executor.migrate([("migrations", "0001_initial")]) + self.assertTableExists("migrations_author") + self.assertTableExists("migrations_tribble") + # And migrate back to clean up the database + executor.loader.build_graph() + executor.migrate([("migrations", None)]) + self.assertTableNotExists("migrations_author") + self.assertTableNotExists("migrations_tribble") diff --git a/tests/migrations/test_migrations_custom_user/0001_initial.py b/tests/migrations/test_migrations_custom_user/0001_initial.py new file mode 100644 index 0000000000..f8e6ce4b0d --- /dev/null +++ b/tests/migrations/test_migrations_custom_user/0001_initial.py @@ -0,0 +1,31 @@ +# encoding: utf8 +from __future__ import unicode_literals + +from django.db import migrations, models +from django.conf import settings + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + + migrations.CreateModel( + "Author", + [ + ("id", models.AutoField(primary_key=True)), + ("name", models.CharField(max_length=255)), + ], + ), + + migrations.CreateModel( + "Tribble", + [ + ("id", models.AutoField(primary_key=True)), + ("author", models.ForeignKey(to=settings.AUTH_USER_MODEL, to_field="id")), + ], + ) + + ] diff --git a/tests/migrations/test_migrations_custom_user/__init__.py b/tests/migrations/test_migrations_custom_user/__init__.py new file mode 100644 index 0000000000..e69de29bb2