2

I'm writing a DB router to control what should be or not applied on the DB, so, implemented allow_migrate().

Here is what I did:

def allow_migrate(self, db, app_label, model_name=None, **hints):
      if app_label == 'django_q':
         return db == 'tasks'
      elif app_label != 'django_q': 
         return db == 'default'

I was expecting that when a router returns False, then an app wouldn't be applied on the current DB at all, it happened somehow, no tables were created, but, the entire app migration list is added to django_migrations table at the DB.

I was expecting that when allow_migrate() return False, then Django won't add anything to current DB about this app, but if this behavior is the expected, then, this is the same as migrate --fake, right? if this so, I prefer doing it manually for the other DB.

I have done some research to see what is actually done when allow_migrate() returns False but got no luck.

Thanks in advance.

Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43
Mahmoud Adel
  • 1,262
  • 2
  • 13
  • 23

0 Answers0