3

I'm trying to make a (Django) query to my database using the following syntax:

Derp.objects.all()

I have a production database and a default (development) database. So obviously, by default, that query above will use the default database.

I'm having trouble figuring out how to select my other database. A coworker suggested the following:

Derp.objects.all(using="development")

But that returns a TypeError:

all() got an unexpected keyword argument 'using'

Can someone tell me what the proper syntax is? I can't seem to find what parameters the all() method will actually accept.

Martin Thurau
7,6847 gold badges46 silver badges80 bronze badges
asked Dec 27, 2011 at 18:39
2
  • The syntax and wording look like you are using the Django ORM. If so it would be helpful to know what version. Commented Dec 27, 2011 at 18:45
  • @MarkLavin django.VERSION prints (1, 3, 0, 'final', 0) Commented Dec 27, 2011 at 18:52

1 Answer 1

2

Your syntax is slightly off:

Derp.objects.using('production').all()

Obviously, the 'production' key needs to match whatever you've labeled your DB in settings.py.

answered Dec 27, 2011 at 18:52
Sign up to request clarification or add additional context in comments.

1 Comment

Also, the database type (PostgreSQL) itself should be irrelevant since you're connecting through ORM.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.