在django中为django-admin提供单独的数据库

[英]having a separate database for django-admin in django


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).

我正在尝试为使用rails编写的应用程序构建用户管理界面,我正在使用django。我已经拥有rails应用程序中的遗留数据库,其中包含我将要管理的内容,并且对于这个新的django应用程序的用户管理,我想使用django-admin。但我不想改变我拥有的遗留数据库的结构。在做syncdb时,我看到django在遗留数据库下创建了所有表,这不是我想要的。我现在所做的是,我在settings.py上定义了多个数据库,遗留数据库是非默认数据库。这样做django在默认数据库上创建了所有与user / auth相关的表,这阻止了旧数据库的结构被更改。但我想知道是否有其他更好的方法,我可以做的事情,如用户,auth,会话等使用数据库A和其他内容使用数据库B(遗留数据库)。

Thanks.

谢谢。

2 个解决方案

#1


4  

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.

您谈论身份验证表。您可以声明2个数据库,django应用程序的主数据库('default')将只包含django.contrib.auth.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/

这里如何处理多个并配置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

如何指定ModelAdmin类来处理多个数据库:https://docs.djangoproject.com/en/dev/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface

#2


2  

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/

您不需要创建第二个数据库。 Django允许您从现有表生成模型。该文档提供了集成现有数据库的方法: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.

总之,使用inspectdb管理命令让Django根据现有数据库为您提供模型。您仍然需要syncdb用于特定于Django的模型,例如权限和内容类型。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/04/23/bb5d227763e63116bbe88246e2de9edf.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号