Is there any way to get syncdb to pull in models that aren't in models.py?

103 views Asked by At

I have a file filled with models embedded deep within my app and not in a models.py file or models directory.

Basically it's a file that points to tables on a legacy database, which is why I put it in a separate file.

However, now that I'm trying to set up a testing version, I need to be able to create all the tables via syncdb.

Is there any way for me to do this? Or must I create the tables manually using SQL?

2

There are 2 answers

0
Ted On BEST ANSWER

temp_app/models.py

from my.deep.in.code.modelfile import model1
from my.deep.in.code.modelfile import model2

Add temp_app to installed apps (make sure you also have init.py in the dir)

Run Syncdb

Remove temp_app from installed apps

0
Jordan Reiter On

forehead slap time

Okay, so this part is key: if you do import models from elsewhere in your project, not within the normal models.py files, make sure you add:

class Meta:
    app_label = 'foo'

Otherwise, the models will be ignored by syncdb!

I did try something along the lines of what Ted wrote but for some reason it wasn't until I added the app_label part that syncdb was able to create the models.