#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 |
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 by , 15 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 14 years ago
I agree. The "database router" solution is a FAR better solution. Glad to have been wrong on this one!
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.