Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#12499 closed (wontfix)

Allow a model's Meta to specify a single multi-db alias

Reported by: crucialfelix <crucialfelix@…> Owned by: nobody
Component: Database layer (models, ORM) Version:
Severity: Keywords: multi-db
Cc: crucialfelix@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Some, perhaps most models are clearly intended to work only with one connection or another in a multi-db project.

Currently you can specify:

objects = ModelManager().db_manager('legacy')

but I think the manager by default could look for:

class Meta:

connection = 'legacy'

and automatically bind to that connection

also I've run into a problem when running tests. the test runner causes each connection to create a test db which then creates all models on all connections.

if a connection does not support gis, or the model is not intended to be run on that connection ever, then the test db shouldn't create that table. thus I think that a model should be able to specify a single connection alias.

the above Meta setting would allow create_test_db to only create tables as needed for that connection.

Change History (2)

comment:1 Changed 13 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

This feature was implemented in an early draft of multi-db, and specifically removed. The database shouldn't be specified as a Meta property - consider the case of reusable apps. If your model defines Meta.connection (the original draft called it Meta.using), you can't share that model with any other Django user without forcing your particular database usage strategy.

comment:2 Changed 11 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top