Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 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: UI/UX:

Description

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.

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.