I have 4 models in my models.py. I am using multiple databases. I want to write only model into the another database I have added. I have default Router from Django documentation:
def db_for_write(self, model, **hints):
"""
Attempts to write fileupload models go to galaxy.
"""
if model._meta.app_label == 'fileupload': #fileupload=app_name
return 'galaxy' #database=galaxy
return None
My model name is GalaxyUser. How can I modify this function so that when I do ./manage.py syncdb --database=galaxy it only writes the model GalaxyUser to the database.
You’ll want to define the
allow_syncdbmethodMake sure the router is in a different file to the models (like
fileupload/routers.py) and that it is installed in yoursettings.pyfile like so:DATABASE_ROUTERS = ['fileupload.routers.GalaxyRouter']