Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#12653 closed (wontfix)

add Meta option when working with multiple databases

Reported by: Chris Curvey Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-alpha
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


when working with multiple databases, I'd like to see the database specifier as an option in the Meta section of models, so that you're not repeating your database names everywhere. For example:


  "default" : {"ENGINE" : "mysql"....},
  "foo" : {"ENGINE" : "postgres"...}

then in your file, you would have:

class Bar(models.Model):
  class Meta:
     db_name = "foo"

The existing "using" method works fine, especially if you are dealing with sharding, but if you're working with models that are just in different physical databases, then it would be nice to be able to specify the location in one place and not every time you do a query (.using("foo")) and every time you do a save ( .save(using="foo"))

(This may exist somewhere and I just can't find it in the docs yet. Django people are sometimes smart like that.)

Change History (2)

comment:1 Changed 9 years ago by Alex Gaynor

Resolution: wontfix
Status: newclosed

This was originally implemented, however it was since rejected (the rationale for this is explained here: If you take a look at the django-developers mailing list Russell Keith-Magee has just proposed a far more comprehensive solution to database pinning and other schemes.

comment:2 Changed 8 years ago by Chris Curvey

I agree. The "database router" solution is a FAR better solution. Glad to have been wrong on this one!

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