[Answered ]-Django models.ForeignKey issue with model with custom foreign key

2👍

It sounds like you have to specify db_column, to let Django know the name of the column in the PatientMed column.

class PatientMed(models.Model):
    circdetect = models.ForeignKey(CircDetect, on_delete=models.CASCADE, db_column='circdetect', to_field='oid')

0👍

You haven’t written the instruction that makes the error. But it seems that you have another table named PatientInfo that the error is related to.

0👍

I’m not sure what was the cause of the problem. I solved it by dropping my database and recreating it and my entities.
Thank you everyone.

👤Alex P

Leave a comment