Hey, thank you for fast response. Yes, I'm aware that allow_migrate format from the one mentioned in link you provided because (as is mentioned in title) I'm using Django 1.7 and the code I provided is almost copy/paste of what you can find under the same link but for v. 1.7 Things I changed in code are data base name and _meta.app_label
W dniu środa, 9 grudnia 2015 22:35:58 UTC+1 użytkownik learn django napisał: > > Hi LP. > > Your allow_migrate function differs in the format from what is mentioned > in the link below. > > https://docs.djangoproject.com/en/dev/topics/db/multi-db/#topics-db-multi-db-routing > > I have tried this last week and it works fine. > > On Wednesday, December 9, 2015 at 2:47:42 AM UTC-8, Łukasz Pauszek wrote: >> >> Hello, >> I'm trying to configure project in Django 1.7 to use multiple databases, >> for now I'm following official documentation to configure 2 dbs. >> Problem is that when I run: ./manage.py makemigrations myapp only changes >> in default database are detected. And ./manage.py migrate >> --database=main_db doesn't see model which should be created in it. >> What should I do to update second database? >> Below I'm pasting code which I think may be relevant: >> >> project/settings.py >> DATABASES = { >> 'default': { >> 'ENGINE': 'django.db.backends.sqlite3', >> 'NAME': os.path.join(BASE_DIR, 'default.sqlite3'), >> }, >> 'main_db': { >> 'ENGINE': 'django.db.backends.sqlite3', >> 'NAME': os.path.join(BASE_DIR, 'main_db.sqlite3') >> } >> } >> >> DATABASE_ROUTERS = ['myapp.routers.SelectDatabaseRouter'] >> >> myapp/models.py >> class TestingDefaultDatabase(models.Model): >> >> class Meta: >> verbose_name = "TestingDefaultDatabase" >> verbose_name_plural = "TestingDefaultDatabases" >> >> name = models.CharField(max_length=50) >> surname = models.CharField(max_length=50) >> >> >> class TestingMainDatabase(models.Model): >> >> class Meta: >> verbose_name = "TestingMainDatabase" >> verbose_name_plural = "TestingMainDatabases" >> app_label = 'main' >> >> name = models.CharField(max_length=50) >> surname = models.CharField(max_length=50) >> >> myapp/routers.py >> class SelectDatabaseRouter(object): >> def db_for_read(self, model, **hints): >> if model._meta.app_label == 'main': >> return 'main_db' >> return None >> >> def db_for_write(self, model, **hints): >> if model._meta.app_label == 'main': >> return 'main_db' >> return None >> >> def allow_relation(self, obj1, obj2, **hints): >> if obj1._meta.app_label == 'main' or \ >> obj2._meta.app_label == 'main': >> return True >> return None >> >> def allow_migrate(self, db, model): >> if db == 'main_db': >> return model._meta.app_label == 'main' >> elif model._meta.app_label == 'main': >> return False >> return None >> >> Am I missing or incorrectly configured something? Or perhaps I'm not >> using appropriate commands? >> Thank you for help. >> ŁP >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a57a9b99-e185-4751-9f73-910198473caa%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

