0

I create project using DRF, I'm using two database alias: Default and Oracle. On oracle database there are all django tables. How can I use authenticate if auth_user is on oracle not default database.

  • Does this answer your question? [How to use auth\_user from another database(not default database)?](https://stackoverflow.com/questions/53928397/how-to-use-auth-user-from-another-databasenot-default-database) – Ahtisham Jan 21 '22 at 13:55

1 Answers1

0

Hello as seen by the documentation of Django you can run multiple databases but you need to re-write most of your Serializers/Views depending on the models you need to retrive/write/delete. Here is the link of the documentation: https://docs.djangoproject.com/en/4.0/topics/db/multi-db/

>>> # This will run on the 'default' database.
>>> Author.objects.all()

>>> # So will this.
>>> Author.objects.using('default').all()

>>> # This will run on the 'replica1' database.
>>> Author.objects.using('replica1').all()


DATABASES = {
    'default': {},
    'auth_db': {
        'NAME': 'auth_db_name',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'swordfish',
    },
    'primary': {
        'NAME': 'primary_name',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'spam',
    },
    'replica1': {
        'NAME': 'replica1_name',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'eggs',
    },
    'replica2': {
        'NAME': 'replica2_name',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'bacon',
    },

}

Gledi
  • 51
  • 1