Hunsu
Hunsu

Reputation: 3381

syncdb doesn't create table models

I'm working on a web application with Django framework. I have this structure :

I defined my models in models.py file. In my settings file I added this line project.web_app in INSTALLED_APPS. When I did

python mange.py syncdb

the models are not created. To create them I must add the project.web_app.models to my settings file. I have looked to others project and they don't do like this and it works. Is it correct what I'm doing?

Upvotes: 0

Views: 777

Answers (2)

daveoncode
daveoncode

Reputation: 19578

models.py should be under your app folder (in your case "web_app").

If you want to separate your models then you have to turn models folder into a python package, in this case add an __init__.py in that folder and make sure that in the init file your models are accessible to the outside world at the path "web_app.models.ModelName".

So, solution 1 (standard Django approach):

  • project
    • web_app
    • models.py

Solution 2:

  • project
    • web_app
    • models
      • __init__.py
      • ModelOne.py
      • ModelTwo.py...

the __init__.py will contains something like:

from .ModelOne import ModelOne
from .ModelTwo import ModelTwo

The approach N2 can be also used for views and other stuff too ;)

Upvotes: 4

Nishant Nawarkhede
Nishant Nawarkhede

Reputation: 8400

First add your app to INSTALLED_APPS , and then run

python manage.py inspectdb > somefile.txt

You can get quickly check out if your database structure is matching your django models.

If python manage.py inspectdb > somefile.txt not created any structure, then make sure that your app is added to to INSTALLED_APPS.

Upvotes: 0

Related Questions