I'm building a website under Django Framework, this website needs to have different SQL schemes, for now I succeeded creating all schemes and all stuff, but I don't understand why the table django_migrations is in each schema after migration of databases.
Expected Databases Content:
AppDB tables are all the models defined by this app
Default DB tables are all Django tables (admin, contenttypes, auth, sessions)
Databases Content:
AppDB tables are all the models defined by this app + django_migrations
DEFAULT tables are all Django tables (admin, contenttypes, auth, sessions) + django_migrations
Those are the routers of the 2 dbs:
class DefaultRouter(object):
APPS = ['auth', 'sessions', 'admin', 'contenttypes']
DB = 'default'
def db_for_read(self, model, **hints):
if model._meta.app_label in self.APPS:
return self.DB
return None
def db_for_write(self, model, **hints):
if model._meta.app_label in self.APPS:
return self.DB
return None
def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label in self.APPS or obj2._meta.app_label in self.APPS:
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label in self.APPS:
return db == self.DB
return None
class MyAppDBRouter(object):
def db_for_read(self, model, **hints):
return self.check_app_label(model)
def db_for_write(self, model, **hints):
return self.check_app_label(model)
def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label == 'myapp' or obj2._meta.app_label == 'myapp':
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label == 'myapp':
return db == 'appdb'
return None
@staticmethod
def check_app_label(model):
if model._meta.app_label == 'myapp':
return 'appdb'
return None
Thanks.