Jordan Reiter
Jordan Reiter

Reputation: 21002

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

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?

Upvotes: 0

Views: 102

Answers (2)

Jordan Reiter
Jordan Reiter

Reputation: 21002

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.

Upvotes: 1

Ted
Ted

Reputation: 12318

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

Upvotes: 2

Related Questions