Fixed #29469 -- Added a helpful makemigrations error if app_label contains dots.

This commit is contained in:
oliver 2018-06-17 04:18:57 +09:00 committed by Tim Graham
parent 998d774195
commit 78972af367
2 changed files with 15 additions and 1 deletions

View File

@ -73,6 +73,14 @@ class Command(BaseCommand):
bad_app_labels.add(app_label) bad_app_labels.add(app_label)
if bad_app_labels: if bad_app_labels:
for app_label in bad_app_labels: for app_label in bad_app_labels:
if '.' in app_label:
self.stderr.write(
"'%s' is not a valid app label. Did you mean '%s'?" % (
app_label,
app_label.split('.')[-1],
)
)
else:
self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label) self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label)
sys.exit(2) sys.exit(2)

View File

@ -786,6 +786,12 @@ class MakeMigrationsTests(MigrationTestBase):
call_command("makemigrations", "this_app_does_not_exist", stderr=err) call_command("makemigrations", "this_app_does_not_exist", stderr=err)
self.assertIn("'this_app_does_not_exist' could not be found.", err.getvalue()) self.assertIn("'this_app_does_not_exist' could not be found.", err.getvalue())
def test_makemigrations_app_name_with_dots(self):
err = io.StringIO()
with self.assertRaises(SystemExit):
call_command('makemigrations', 'invalid.app.label', stderr=err)
self.assertIn("'invalid.app.label' is not a valid app label. Did you mean 'label'?", err.getvalue())
def test_makemigrations_empty_no_app_specified(self): def test_makemigrations_empty_no_app_specified(self):
""" """
makemigrations exits if no app is specified with 'empty' mode. makemigrations exits if no app is specified with 'empty' mode.