Mirage
Mirage

Reputation: 31548

Using raw sql in django python

I have few things to ask for custom queries in Django

  1. DO i need to use the DB table name in the query or just the Model name
  2. if i need to join the various tables in raw sql. do i need to use db field name or model field name like

Person.objects.raw('SELECT id, first_name, last_name, birth_date FROM Person A inner join Address B on A.address = B.id ')

or B.id = A.address_id

Upvotes: 0

Views: 426

Answers (1)

Jamey Sharp
Jamey Sharp

Reputation: 8491

You need to use the database's table and field names in the raw query--the string you provide will be passed to the database, not interpreted by the Django ORM.

Upvotes: 3

Related Questions