More useful error message when defining ForeignKey with invalid first argument
|Reported by:||Jonas Obrist||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.5|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When you create a ForeignKey with an invalid first argument (for example None), you get an error message:
AssertionError: ForeignKey(None) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'
What this does not tell you is what model in what app and what field this error occurs.
I therefore propose that this check is moved to contribute_to_class where we have all the information.
(For the record if anyone stumbles up on this, you can use
--traceback which will give you this information)