From 2928019e0ccd8e9c7d3a3fba7722a7af87018e5d Mon Sep 17 00:00:00 2001 From: Chinmoy Chakraborty Date: Fri, 5 Jun 2020 21:32:21 +0530 Subject: [PATCH] Fixed #31645 -- Enhanced the migration warning for migrate commmand. Added the list of apps with changes not reflected in migrations. --- django/core/management/commands/migrate.py | 5 ++-- tests/migrations/test_commands.py | 34 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index 81696f11c1..a65500d76a 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -227,8 +227,9 @@ class Command(BaseCommand): changes = autodetector.changes(graph=executor.loader.graph) if changes: self.stdout.write(self.style.NOTICE( - " Your models have changes that are not yet reflected " - "in a migration, and so won't be applied." + " Your models in app(s): %s have changes that are not " + "yet reflected in a migration, and so won't be " + "applied." % ", ".join(repr(app) for app in sorted(changes)) )) self.stdout.write(self.style.NOTICE( " Run 'manage.py makemigrations' to make new " diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index f7b21931e4..78cada9106 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -890,6 +890,40 @@ class MigrateTests(MigrationTestBase): applied_migrations = recorder.applied_migrations() self.assertNotIn(("migrations", "0001_initial"), applied_migrations) + @override_settings(INSTALLED_APPS=[ + 'migrations.migrations_test_apps.migrated_unapplied_app', + 'migrations.migrations_test_apps.migrated_app', + ]) + def test_migrate_not_reflected_changes(self): + class NewModel1(models.Model): + class Meta(): + app_label = 'migrated_app' + + class NewModel2(models.Model): + class Meta(): + app_label = 'migrated_unapplied_app' + + out = io.StringIO() + try: + call_command('migrate', verbosity=0) + call_command('migrate', stdout=out, no_color=True) + self.assertEqual( + "operations to perform:\n" + " apply all migrations: migrated_app, migrated_unapplied_app\n" + "running migrations:\n" + " no migrations to apply.\n" + " your models in app(s): 'migrated_app', " + "'migrated_unapplied_app' have changes that are not yet " + "reflected in a migration, and so won't be applied.\n" + " run 'manage.py makemigrations' to make new migrations, and " + "then re-run 'manage.py migrate' to apply them.\n", + out.getvalue().lower(), + ) + finally: + # Unmigrate everything. + call_command('migrate', 'migrated_app', 'zero', verbosity=0) + call_command('migrate', 'migrated_unapplied_app', 'zero', verbosity=0) + class MakeMigrationsTests(MigrationTestBase): """