summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2023-11-08 22:29:07 +0000
committerNatalia <124304+nessita@users.noreply.github.com>2023-11-09 10:44:07 -0300
commit8eba6efbf08d3fe5d64bd92948c2c86ab4f07608 (patch)
treeeee2c3851b19af64cc1fc62c7274c2b0d3740329
parent97a78121b376e3d0818a25b5f0b2e5b5323a4c15 (diff)
[5.0.x] Fixed #34457 -- Restored output for makemigrations --check.
Co-authored-by: David Sanders <shang.xiao.sanders@gmail.com> Co-authored-by: Natalia <124304+nessita@users.noreply.github.com> Backport of f7389c4b07ceeb036436e065898e411b247bca78 from main
-rw-r--r--django/core/management/commands/makemigrations.py8
-rw-r--r--docs/ref/django-admin.txt2
-rw-r--r--docs/releases/4.2.8.txt3
-rw-r--r--tests/migrations/test_commands.py25
4 files changed, 28 insertions, 10 deletions
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index 35661d4997..22498af3c0 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -72,7 +72,7 @@ class Command(BaseCommand):
dest="check_changes",
help=(
"Exit with a non-zero status if model changes are missing migrations "
- "and don't actually write them."
+ "and don't actually write them. Implies --dry-run."
),
)
parser.add_argument(
@@ -114,6 +114,8 @@ class Command(BaseCommand):
raise CommandError("The migration name must be a valid Python identifier.")
self.include_header = options["include_header"]
check_changes = options["check_changes"]
+ if check_changes:
+ self.dry_run = True
self.scriptable = options["scriptable"]
self.update = options["update"]
# If logs and prompts are diverted to stderr, remove the ERROR style.
@@ -251,12 +253,12 @@ class Command(BaseCommand):
else:
self.log("No changes detected")
else:
- if check_changes:
- sys.exit(1)
if self.update:
self.write_to_last_migration_files(changes)
else:
self.write_migration_files(changes)
+ if check_changes:
+ sys.exit(1)
def write_to_last_migration_files(self, changes):
loader = MigrationLoader(connections[DEFAULT_DB_ALIAS])
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
index ac19c5a8f8..f533aa11de 100644
--- a/docs/ref/django-admin.txt
+++ b/docs/ref/django-admin.txt
@@ -742,7 +742,7 @@ Generate migration files without Django version and timestamp header.
.. django-admin-option:: --check
Makes ``makemigrations`` exit with a non-zero status when model changes without
-migrations are detected.
+migrations are detected. Implies ``--dry-run``.
.. versionchanged:: 4.2
diff --git a/docs/releases/4.2.8.txt b/docs/releases/4.2.8.txt
index b8bf62cdc9..5804589408 100644
--- a/docs/releases/4.2.8.txt
+++ b/docs/releases/4.2.8.txt
@@ -9,4 +9,5 @@ Django 4.2.8 fixes several bugs in 4.2.7.
Bugfixes
========
-* ...
+* Fixed a regression in Django 4.2 that caused :option:`makemigrations --check`
+ to stop displaying pending migrations (:ticket:`34457`).
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 387cef924a..a9c1cdf893 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -2392,20 +2392,35 @@ class MakeMigrationsTests(MigrationTestBase):
"makemigrations", "migrations", "--name", "invalid name", "--empty"
)
- def test_makemigrations_check(self):
+ def test_makemigrations_check_with_changes(self):
"""
makemigrations --check should exit with a non-zero status when
there are changes to an app requiring migrations.
"""
+ out = io.StringIO()
with self.temporary_migration_module() as tmpdir:
- with self.assertRaises(SystemExit):
- call_command("makemigrations", "--check", "migrations", verbosity=0)
- self.assertFalse(os.path.exists(tmpdir))
+ with self.assertRaises(SystemExit) as cm:
+ call_command(
+ "makemigrations",
+ "--check",
+ "migrations",
+ stdout=out,
+ )
+ self.assertEqual(os.listdir(tmpdir), ["__init__.py"])
+ self.assertEqual(cm.exception.code, 1)
+ self.assertIn("Migrations for 'migrations':", out.getvalue())
+ def test_makemigrations_check_no_changes(self):
+ """
+ makemigrations --check should exit with a zero status when there are no
+ changes.
+ """
+ out = io.StringIO()
with self.temporary_migration_module(
module="migrations.test_migrations_no_changes"
):
- call_command("makemigrations", "--check", "migrations", verbosity=0)
+ call_command("makemigrations", "--check", "migrations", stdout=out)
+ self.assertEqual("No changes detected in app 'migrations'\n", out.getvalue())
def test_makemigrations_migration_path_output(self):
"""