mirror of
https://github.com/django/django.git
synced 2025-02-28 19:44:35 +00:00
[4.2.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
This commit is contained in:
parent
3d2370607d
commit
90c3d71dfe
@ -72,7 +72,7 @@ class Command(BaseCommand):
|
|||||||
dest="check_changes",
|
dest="check_changes",
|
||||||
help=(
|
help=(
|
||||||
"Exit with a non-zero status if model changes are missing migrations "
|
"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(
|
parser.add_argument(
|
||||||
@ -114,6 +114,8 @@ class Command(BaseCommand):
|
|||||||
raise CommandError("The migration name must be a valid Python identifier.")
|
raise CommandError("The migration name must be a valid Python identifier.")
|
||||||
self.include_header = options["include_header"]
|
self.include_header = options["include_header"]
|
||||||
check_changes = options["check_changes"]
|
check_changes = options["check_changes"]
|
||||||
|
if check_changes:
|
||||||
|
self.dry_run = True
|
||||||
self.scriptable = options["scriptable"]
|
self.scriptable = options["scriptable"]
|
||||||
self.update = options["update"]
|
self.update = options["update"]
|
||||||
# If logs and prompts are diverted to stderr, remove the ERROR style.
|
# If logs and prompts are diverted to stderr, remove the ERROR style.
|
||||||
@ -251,12 +253,12 @@ class Command(BaseCommand):
|
|||||||
else:
|
else:
|
||||||
self.log("No changes detected")
|
self.log("No changes detected")
|
||||||
else:
|
else:
|
||||||
if check_changes:
|
|
||||||
sys.exit(1)
|
|
||||||
if self.update:
|
if self.update:
|
||||||
self.write_to_last_migration_files(changes)
|
self.write_to_last_migration_files(changes)
|
||||||
else:
|
else:
|
||||||
self.write_migration_files(changes)
|
self.write_migration_files(changes)
|
||||||
|
if check_changes:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def write_to_last_migration_files(self, changes):
|
def write_to_last_migration_files(self, changes):
|
||||||
loader = MigrationLoader(connections[DEFAULT_DB_ALIAS])
|
loader = MigrationLoader(connections[DEFAULT_DB_ALIAS])
|
||||||
|
@ -738,7 +738,7 @@ Generate migration files without Django version and timestamp header.
|
|||||||
.. django-admin-option:: --check
|
.. django-admin-option:: --check
|
||||||
|
|
||||||
Makes ``makemigrations`` exit with a non-zero status when model changes without
|
Makes ``makemigrations`` exit with a non-zero status when model changes without
|
||||||
migrations are detected.
|
migrations are detected. Implies ``--dry-run``.
|
||||||
|
|
||||||
.. versionchanged:: 4.2
|
.. versionchanged:: 4.2
|
||||||
|
|
||||||
|
@ -9,4 +9,5 @@ Django 4.2.8 fixes several bugs in 4.2.7.
|
|||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed a regression in Django 4.2 that caused :option:`makemigrations --check`
|
||||||
|
to stop displaying pending migrations (:ticket:`34457`).
|
||||||
|
@ -2386,20 +2386,35 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||||||
"makemigrations", "migrations", "--name", "invalid name", "--empty"
|
"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
|
makemigrations --check should exit with a non-zero status when
|
||||||
there are changes to an app requiring migrations.
|
there are changes to an app requiring migrations.
|
||||||
"""
|
"""
|
||||||
|
out = io.StringIO()
|
||||||
with self.temporary_migration_module() as tmpdir:
|
with self.temporary_migration_module() as tmpdir:
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit) as cm:
|
||||||
call_command("makemigrations", "--check", "migrations", verbosity=0)
|
call_command(
|
||||||
self.assertFalse(os.path.exists(tmpdir))
|
"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(
|
with self.temporary_migration_module(
|
||||||
module="migrations.test_migrations_no_changes"
|
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):
|
def test_makemigrations_migration_path_output(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user