Opened 10 years ago
Closed 10 years ago
#24547 closed Cleanup/optimization (worksforme)
Errors for paths for Model relationships in other apps can be misleading / confusing
Reported by: | andrei kulakov | Owned by: | andrei kulakov |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | error message, warning |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If a user is creating a relationship to a model in another app, it would be natural to use a path like: ForeignKey('app2.models.Model2'). This is consistent with e.g. urlconf where views are referenced like 'myapp.views.my_view', or generally django imports that use dots to separate elements of a full path.
The error you would get looks like this:
app2.M1.f3: (fields.E300) Field defines a relation with model 'app3.models.M1', which is either not installed, or is abstract.
It might seem like it's not a big deal -- user just has to look at the docs or google for the error.
However, in some cases it may lead to some loss of time, for example I had circular foreign key dependencies between models for testing and thought the error is due to circular references. More generally, django errors can result from seemingly unrelated causes so if a user starts with a firm assumption that a full path needs to be given, the error might lead them to look for all kinds of workarounds to try before coming back to the path format.
It would be easy for django to check the path and, if there are more than one dot in path, and specifically if '.models.' is included in path, a hint should be shown along with the error:
NOTE: path should be of the form 'myapp.MyModel' and should NOT include the name of module containing models (which is usually 'models').
Change History (4)
comment:1 by , 10 years ago
Component: | Migrations → Database layer (models, ORM) |
---|---|
Easy pickings: | unset |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 10 years ago
comment:4 by , 10 years ago
Resolution: | → worksforme |
---|---|
Status: | assigned → closed |
I no longer get the error in description, instead I get this traceback:
So it looks like this was changed and the original error can no longer be triggered?
Unless there's some circumstances that can trigger the original error (I couldn't find any -- tried both creating initial migration, creating a new table, adding to existing table), this ticket should be closed.