Fixed #31645 -- Enhanced the migration warning for migrate commmand.

Added the list of apps with changes not reflected in migrations.
This commit is contained in:
Chinmoy Chakraborty 2020-06-05 21:32:21 +05:30 committed by Mariusz Felisiak
parent aeb8996a67
commit 2928019e0c
2 changed files with 37 additions and 2 deletions

View File

@ -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 "

View File

@ -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):
"""