When you use makemigrations, and pass the full dotted path to this
command, the error message is somewhat misleading:
{{{
App 'integrations.systems.generic.importers' could not be found. Is it in
INSTALLED_APPS?
}}}
In this case, I have that exact string in my INSTALLED_APPS, but
makemigrations is expecting just the app_label. Perhaps we could improve
the error message when dots are detected in the app_label, suggesting how
to fix it: or even look at just the last part of the path?
--
Ticket URL: <https://code.djangoproject.com/ticket/29469>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => Migrations
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:1>
Comment (by Windson yang):
Maybe you should add an example project?
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:2>
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:3>
* owner: nobody => oliver
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:4>
* owner: oliver => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:5>
* status: new => assigned
* owner: (none) => oliver
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:6>
Comment (by oliver):
Current code generating that error message is as follows when using
makemigraions command.
{{{
# Make sure the app they asked for exists
app_labels = set(app_labels)
bad_app_labels = set()
for app_label in app_labels:
try:
apps.get_app_config(app_label)
except LookupError:
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)
sys.exit(2)
}}}
and below is the part that checks the validity of the app name when using
startapp and createproject command
{{{
if not name.isidentifier():
raise CommandError(
"'{name}' is not a valid {app} name. Please make sure the
"
"name is a valid identifier.".format(
name=name,
app=app_or_project,
)
)
}}}
How about using the code validating app name to current code as follows?
https://github.com/django/django/pull/10051
{{{
# Make sure the app they asked for is a valid app name and exist.
app_labels = set(app_labels)
bad_app_labels = set()
for app_label in app_labels:
try:
apps.get_app_config(app_label)
except LookupError:
bad_app_labels.add(app_label)
if bad_app_labels:
for app_label in bad_app_labels:
if not app_label.isidentifier():
self.stderr.write(
"'%s' is not a valid app name. Please make sure
the "
"name is a valid identifire."% app_label
)
else:
self.stderr.write("App '%s' could not be found. Is it
in INSTALLED_APPS?" % app_label)
sys.exit(2)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:7>
* has_patch: 0 => 1
* needs_tests: 0 => 1
Comment:
[https://github.com/django/django/pull/10052 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:8>
Comment (by oliver):
https://github.com/django/django/pull/10057
I change the target branch to master and add a test.
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"78972af367a1da54aa7e539e4b1ffa2b56571e77" 78972af3]:
{{{
#!CommitTicketReference repository=""
revision="78972af367a1da54aa7e539e4b1ffa2b56571e77"
Fixed #29469 -- Added a helpful makemigrations error if app_label contains
dots.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"d03b130cbcc629daa5ae767588b2fff41ea1e48a" d03b130c]:
{{{
#!CommitTicketReference repository=""
revision="d03b130cbcc629daa5ae767588b2fff41ea1e48a"
[2.1.x] Fixed #29469 -- Added a helpful makemigrations error if app_label
contains dots.
Backport of 78972af367a1da54aa7e539e4b1ffa2b56571e77 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"c3c7d15c34d6174ff25a49d7c9a57da140769567" c3c7d15]:
{{{
#!CommitTicketReference repository=""
revision="c3c7d15c34d6174ff25a49d7c9a57da140769567"
Refs #29469 -- Reused get_app_config() error message in makemigrations
error.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29469#comment:12>