mirror of https://github.com/django/django.git
Refs #29469 -- Reused get_app_config() error message in makemigrations error.
This commit is contained in:
parent
abbc9cd71c
commit
c3c7d15c34
|
@ -65,23 +65,14 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# Make sure the app they asked for exists
|
# Make sure the app they asked for exists
|
||||||
app_labels = set(app_labels)
|
app_labels = set(app_labels)
|
||||||
bad_app_labels = set()
|
has_bad_labels = False
|
||||||
for app_label in app_labels:
|
for app_label in app_labels:
|
||||||
try:
|
try:
|
||||||
apps.get_app_config(app_label)
|
apps.get_app_config(app_label)
|
||||||
except LookupError:
|
except LookupError as err:
|
||||||
bad_app_labels.add(app_label)
|
self.stderr.write(str(err))
|
||||||
if bad_app_labels:
|
has_bad_labels = True
|
||||||
for app_label in bad_app_labels:
|
if has_bad_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)
|
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# Load the current graph state. Pass in None for the connection so
|
# Load the current graph state. Pass in None for the connection so
|
||||||
|
|
|
@ -1408,20 +1408,20 @@ class AppLabelErrorTests(TestCase):
|
||||||
app. 'django.contrib.auth' must be in INSTALLED_APPS for some of these
|
app. 'django.contrib.auth' must be in INSTALLED_APPS for some of these
|
||||||
tests.
|
tests.
|
||||||
"""
|
"""
|
||||||
|
nonexistent_app_error = "No installed app with label 'nonexistent_app'."
|
||||||
|
did_you_mean_auth_error = (
|
||||||
|
"No installed app with label 'django.contrib.auth'. Did you mean "
|
||||||
|
"'auth'?"
|
||||||
|
)
|
||||||
|
|
||||||
def test_makemigrations_nonexistent_app_label(self):
|
def test_makemigrations_nonexistent_app_label(self):
|
||||||
err = io.StringIO()
|
err = io.StringIO()
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
call_command('makemigrations', 'nonexistent_app', stderr=err)
|
call_command('makemigrations', 'nonexistent_app', stderr=err)
|
||||||
self.assertIn(
|
self.assertIn(self.nonexistent_app_error, err.getvalue())
|
||||||
"App 'nonexistent_app' could not be found. Is it in "
|
|
||||||
"INSTALLED_APPS?", err.getvalue()
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_makemigrations_app_name_specified_as_label(self):
|
def test_makemigrations_app_name_specified_as_label(self):
|
||||||
err = io.StringIO()
|
err = io.StringIO()
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
call_command('makemigrations', 'django.contrib.auth', stderr=err)
|
call_command('makemigrations', 'django.contrib.auth', stderr=err)
|
||||||
self.assertIn(
|
self.assertIn(self.did_you_mean_auth_error, err.getvalue())
|
||||||
"'django.contrib.auth' is not a valid app label. Did you mean 'auth'?",
|
|
||||||
err.getvalue()
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue