There is a similar question here - Raw query must include the primary key
However I'm running off of a legacy DB and therefore can't figure out what the issue is with the Primary Key.
This is my RAW query -
trg = Trgjob.objects.db_manager('AdmiralDEV').raw("""
SELECT jobdep_id, jm.jobmst_id, jobdep_type, (jm1.jobmst_prntname + '\' + jm1.jobmst_name) AS jobdep_jobmst,
jobdep_operator, jobdep_status, jobdep_joblogic, jobdep_ingroup, jobdep_dateoffset, jobdep_instoffset,
jobdep_canignore, jobdep_filename, jobdep_filetype, jobdep_fileextent, nodmst_id, varmst_id, jobdep_value
FROM Jobdep jd
INNER JOIN Jobmst jm ON jd.jobmst_id = jm.jobmst_id
INNER JOIN Jobmst jm1 ON jd.jobdep_jobmst = jm1.jobmst_id
WHERE jm.jobmst_id = 9878""")
On the DB works fine, but in django I get the following failure -
Raw query must include the primary key
The primary key on this model is "jobdep_id" as seen in the models.py here -
class Jobdep(models.Model):
jobdep_id = models.IntegerField(primary_key=True)
Try to write query as:
"SELECT jobdep_id AS id ..."
maybe it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With