mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #23407 -- Extended coverage of makemigrations --noinput option.
Changed --noinput option in makemigrations to suppress all user prompts, not just when combined with --merge.
This commit is contained in:
committed by
Markus Holtermann
parent
794c3f74c3
commit
e272904ff7
@@ -9,6 +9,7 @@ from django.db.migrations.autodetector import MigrationAutodetector
|
||||
from django.db.migrations.loader import MigrationLoader
|
||||
from django.db.migrations.questioner import (
|
||||
InteractiveMigrationQuestioner, MigrationQuestioner,
|
||||
NonInteractiveMigrationQuestioner,
|
||||
)
|
||||
from django.db.migrations.state import ProjectState
|
||||
from django.db.migrations.writer import MigrationWriter
|
||||
@@ -93,11 +94,15 @@ class Command(BaseCommand):
|
||||
if self.merge and conflicts:
|
||||
return self.handle_merge(loader, conflicts)
|
||||
|
||||
if self.interactive:
|
||||
questioner = InteractiveMigrationQuestioner(specified_apps=app_labels, dry_run=self.dry_run)
|
||||
else:
|
||||
questioner = NonInteractiveMigrationQuestioner(specified_apps=app_labels, dry_run=self.dry_run)
|
||||
# Set up autodetector
|
||||
autodetector = MigrationAutodetector(
|
||||
loader.project_state(),
|
||||
ProjectState.from_apps(apps),
|
||||
InteractiveMigrationQuestioner(specified_apps=app_labels, dry_run=self.dry_run),
|
||||
questioner,
|
||||
)
|
||||
|
||||
# If they want to make an empty migration, make one for each app
|
||||
|
||||
@@ -180,3 +180,14 @@ class InteractiveMigrationQuestioner(MigrationQuestioner):
|
||||
"Do you want to merge these migration branches? [y/N]",
|
||||
False,
|
||||
)
|
||||
|
||||
|
||||
class NonInteractiveMigrationQuestioner(MigrationQuestioner):
|
||||
|
||||
def ask_not_null_addition(self, field_name, model_name):
|
||||
# We can't ask the user, so act like the user aborted.
|
||||
sys.exit(3)
|
||||
|
||||
def ask_not_null_alteration(self, field_name, model_name):
|
||||
# We can't ask the user, so set as not provided.
|
||||
return NOT_PROVIDED
|
||||
|
||||
Reference in New Issue
Block a user