Reputation: 1994
Ran into a small problem today. Was easily fixed with a bit of research, but wanted to throw it up here in case anyone had something similar.
My app file layout was like so:
>cart
-->Models
----> __init__.py
----> cart.py
----> items.py
--> __init__.py
So I did not have a standard models.py
file, obviously. I wanted to run python manage.py sqlall cart
in order to see the sql code to insert it in my SQL Server database. The problem was, every time I ran that code, it returned nothing. What's the fix?
Upvotes: 3
Views: 587
Reputation: 1994
Well, that makes sense, because it is looking for a models.py
file and not finding one, only Models
submodule.
You have to use app_label on each of the sub-model items. So both the cart.py
and items.py
files need their Meta
tags edited to be have:
class Meta:
app_label="cart"
This tells Django that this model belongs to that app, explicitly. As the Django Docs say,
If a model exists outside of the standard models.py (for instance, if the app’s models are in submodules of myapp.models), the model must define which app it is part of
Then, the sqlall <app>
command should work as you want it too.
Upvotes: 2