Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#12653 closed (wontfix)

add Meta option when working with multiple databases

Reported by: ccurvey 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: UI/UX:

Description

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:

in settings.py:

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

then in your model.py 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 5 years ago by Alex

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

This was originally implemented, however it was since rejected (the rationale for this is explained here: http://alexgaynor.net/2009/nov/27/why-metausing-was-removed/). 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 4 years ago by ccurvey

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