I am trying to build a user management interface for an app that is written in rails, I am using django for the purpose. I already have the legacy database from the rails app, which contains the content that I would be managing, and for user management on this new django app, I want to use django-admin. But I do not want to alter the structure of the legacy database I have. When doing, syncdb, I saw that django created all the tables under the legacy database, which is not what I want. What I have done for now is, I have defined multiple databases on settings.py, the legacy database being the non-default. Doing so django created all the user / auth related tables on the default database, which prevented the structure of legacy database from being altered. But I want to know if there are any other better way, where I could do something like, for user,auth,sessions etc use database A and for other contents use database B(legacy database).
Thanks.
You talk about Authentication tables. You may declare 2 databases, the main database ('default') of your django app will only contains the django.contrib.auth.models models.
Your other ones will be inspected. You'll set database name in your generated models's admin and it should works magically.
Here how to handle multiple and configure db: https://docs.djangoproject.com/en/dev/topics/db/multi-db/
How you specify your ModelAdmin class to handle multiple database: https://docs.djangoproject.com/en/dev/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface
You don't need to create a second database. Django lets you generate models from existing tables. The documentation has a how-to for integrating existing databases: https://docs.djangoproject.com/en/dev/howto/legacy-databases/
In summary use the inspectdb
management command to have Django give you models based on the existing database. You'll still need to syncdb for the Django-specific models such as permissions and content types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With