문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top