So I am working on a project where every application has its own database. However, when I sync the database, only the default database is synced. I need help to see the issue.
# from settings.py
try:
from local_settings import *
INSTALLED_APPS += LOCAL_APPS
for app in LOCAL_APPS:
_appdb = DATABASES['default'].copy()
_appdb['NAME'] = app
DATABASES[app] = _appdb
except ImportError:
pass
I have already verified that each local app has a corresponding database generated dynamically. Here is the db router
import os
MY_LOCAL_APPS = []
with open(os.path.join(os.path.dirname(__file__), "apps.csv")) as appsfile:
MY_LOCAL_APPS = appsfile.readlines()
MY_LOCAL_APPS = [x.strip() for x in MY_LOCAL_APPS]
class JauntRouter(object):
def db_for_read(self, model, **hints):
"""
Attempts to read app models go to app_db.
"""
if model._meta.app_label in MY_LOCAL_APPS:
return model._meta.app_label
return None
def db_for_write(self, model, **hints):
"""
Attempts to write app models go to app_db.
"""
if model._meta.app_label in MY_LOCAL_APPS:
return model._meta.app_label
return None
def allow_relation(self, obj1, obj2, **hints):
if model._meta.app_label in MY_LOCAL_APPS:
return model._meta.app_label
return None
def allow_syncdb(self, db, model):
if db in MY_LOCAL_APPS:
return model._meta.app_label == db
return None
When I run syncdb however, tables are created in the default database. Please note that I have printed out the INSTALLED_APPS and DATABASES from the settings file and they appear correct so I don't think that is the issue.
Help will be greatly appreciated.