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.

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.

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

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.