﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34121	Multi Databases documenation example doesn't work	Jan Przychodniak	nobody	"I have been following this documentation:

https://docs.djangoproject.com/en/4.1/topics/db/multi-db/

Here's my Router setup:

{{{
class AuthRouter:
    """"""
    A router to control all database operations on models in the
    auth and contenttypes applications.
    """"""
    route_app_labels = ('auth', 'contenttypes')
    TARGET_DB = 'users'

    def db_for_read(self, model, **hints):
        """"""
        Attempts to read auth and contenttypes models go to auth_db.
        """"""
        if model._meta.app_label in self.route_app_labels:
            return self.TARGET_DB
        return None

    def db_for_write(self, model, **hints):
        """"""
        Attempts to write auth and contenttypes models go to auth_db.
        """"""
        if model._meta.app_label in self.route_app_labels:
            return self.TARGET_DB
        return None

    def allow_relation(self, obj1, obj2, **hints):
        """"""
        Allow relations if a model in the auth or contenttypes apps is
        involved.
        """"""
        if (
            obj1._meta.app_label in self.route_app_labels or
            obj2._meta.app_label in self.route_app_labels
        ):
           return True
        return None

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        """"""
        Make sure the auth and contenttypes apps only appear in the
        'auth_db' database.
        """"""
        if app_label in self.route_app_labels:
            return db == self.TARGET_DB
        return None
}}}


Here are my settings (kept everything else default):

{{{
DATABASES = {
    'default': {
        'HOST': 'localhost',
        'NAME': 'dev01',
        'ENGINE': 'django.db.backends.postgresql',
        'USER': 'postgres',
        'PASSWORD': 'Admin123!',
        'PORT': '5432',
    },
    'users': {
        'HOST': 'localhost',
        'NAME': 'dev01',
        'ENGINE': 'django.db.backends.postgresql',
        'USER': 'postgres',
        'PASSWORD': 'Admin123!',
        'PORT': '5433',
    }
}

DATABASE_ROUTERS = ['multidb.routers.AuthRouter']
}}}


Migrations are applied correctly on ""users"" database, however when attempting to apply them on default databse I get an error during {{{ Applying admin.0001_initial...Traceback (most recent call last): }}}

Error states: {{{ django.db.utils.ProgrammingError: relation ""django_content_type"" does not exist }}}

Well, logically so - such table is not present in this database. But I defined the router exactly as the documentation told me to. Therefore based on what I see in the documentation I labeled it as a bug in this report."	Bug	closed	Database layer (models, ORM)	4.1	Normal	invalid			Unreviewed	0	0	0	0	0	0
