Skip to content

Commit

Permalink
Fixed #29469 -- Added a helpful makemigrations error if app_label con…
Browse files Browse the repository at this point in the history
…tains dots.
  • Loading branch information
myungsegyo authored and timgraham committed Jun 16, 2018
1 parent 998d774 commit 78972af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion django/core/management/commands/makemigrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ def handle(self, *app_labels, **options):
bad_app_labels.add(app_label)
if bad_app_labels:
for app_label in bad_app_labels:
self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label)
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)
sys.exit(2)

# Load the current graph state. Pass in None for the connection so
Expand Down
6 changes: 6 additions & 0 deletions tests/migrations/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,12 @@ def test_makemigrations_no_app_sys_exit(self):
call_command("makemigrations", "this_app_does_not_exist", stderr=err)
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):
"""
makemigrations exits if no app is specified with 'empty' mode.
Expand Down

0 comments on commit 78972af

Please sign in to comment.