we’have got a somewhat different folder structure within our apps. Currently it looks like this:
When the models are used somewhere, then they correctly get identified and the migrations are created. But if we first create the models (which means they’re unused for a little while), running
No changes detected. Is there a way to circumvent this?
Django specifically looks for models in
models.py (as you discovered). In your
models.py file, you could do:
from app.domain.models import *
# Or, be explicit.
from app.domain.models import DomainThingy
That would expose any models that you’ve created somewhere else to the framework.
Got it. Thanks a lot @mblayman.
But if Django only looks for objects in
models.py, how come the rest of our apps work? The only difference to those apps is that the models are used (i.e. accessed by at least one route), but there is still no top-level
models.py. Should that make a difference?
That’s interesting. I’m not sure what makes a difference to be honest. I’d have to read the source to see how Django imports the
model.py modules to see the details.