#34121: Multi Databases documenation example doesn't work
-------------------------------------+-------------------------------------
               Reporter:  MasteroPL  |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34121>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018413834ff2-38415e4f-d603-4c6a-87bf-37be5edba7e9-000000%40eu-central-1.amazonses.com.

Reply via email to