Having a separate database for django-admin in django

I am trying to create a user management interface for an application written in rails, I am using django for this purpose. I already have an outdated database from the rails application that contains the content that I would manage, and I want to use django-admin to manage users in this new django application. But I do not want to change the structure of the existing database that I have. When doing syncdb, I saw that django created all the tables in the old database, which I don't want. What I did now, I defined several databases on settings.py, an outdated database is not defaulted. Thus, django created all the user-related / auth tables in the default database, which prevented the structure of the obsolete database from being changed. But I want to know if there is another better way where I could do something like: for users, auth, sessions, etc. Use database A, and for other content use database B (deprecated database).

Thanks.

+7
source share
2 answers

You are talking about authentication tables. You can declare 2 databases, the main database ("default") of your django application will only contain django.contrib.auth.models models.

Your others will be checked. You will set the database name in your created model manager, and this should work magically.

Here's how to handle multiple and configure db: https://docs.djangoproject.com/en/dev/topics/db/multi-db/

How do you define your ModelAdmin class to handle multiple databases: https://docs.djangoproject.com/en/dev/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface

+4
source

You do not need to create a second database. Django allows you to create models from existing tables. The documentation has practical applications for integrating existing databases: https://docs.djangoproject.com/en/dev/howto/legacy-databases/

inspectdb , use the inspectdb management inspectdb so that Django provides you with models based on an existing database. You still need to synchronize Django-specific models, such as permissions and content types.

+2
source

All Articles