mirror of
https://github.com/django/django.git
synced 2025-01-03 15:06:09 +00:00
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>
This commit is contained in:
parent
427f0ed98d
commit
f7389c4b07
@ -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])
|
||||
|
@ -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``.
|
||||
|
||||
.. django-admin-option:: --scriptable
|
||||
|
||||
|
@ -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`).
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user