Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL and Django Query

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.

like image 799
tnw Avatar asked Aug 19 '26 04:08

tnw


1 Answers

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.

like image 78
Jordan Avatar answered Aug 21 '26 16:08

Jordan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!