i ask how set models specific database . i'm still new django , read database routing in django website, have 2 models, usermod , adminmod.
usermod should go database userdb.
adminmod should go database admindb.
when migrated it, both table exist in both database. have included app_label on meta, still not working. using django 1.8
edit: trying on userdb while , use admindb. code:
routers.py
class router(object): def db_for_read(self, model, **hints): if model._meta.app_label == 'userdb': return 'userdb' return none def db_for_write(self, model, **hints): if model._meta.app_label == 'userdb': return 'userdb' return none def allow_relation(self, obj1, obj2, **hints): if obj1._meta.app_label == 'userdb' or\ obj2._meta.app_label == 'userdb': return true return none def allow_migrate(self, db, app_label, model=none, **hints): if app_label == 'userdb': return db == 'userdb' return none
try this:
class usermod(models.model): name = models.charfield(max_length=120) class meta: db_table='userdb'
Comments
Post a Comment