UndefinedColumn column integrations_externalrecord.oppcontact_id does not exist django postgresql

Viewed 15

When accessing my ExternalRecord model via the django admin screen, or by querying ExternalRecord.objects.all(), I receive the error: psycopg2.errors.UndefinedColumn: column integrations_externalrecord.oppcontact_id does not exist

I am building an integration functionality, and we have a junction table that houses an external id and the instance in our database that corresponds to this external id, set up like so:

class ExternalRecord(UUIDPrimaryKey, CreatedModifiedMixin, models.Model):
integration = models.ForeignKey(
    to=Integration,
    related_name='external_records',
    on_delete=models.CASCADE
)

emailuser = models.ForeignKey(
    "accounts.EmailUser",
    related_name='external_records',
    null=True,
    blank=True,
    on_delete=models.CASCADE
)

institution = models.ForeignKey(
    "institutions.Institution",
    related_name='external_records',
    null=True,
    blank=True,
    on_delete=models.CASCADE
)

oppcontact = models.ForeignKey(
    "opp_contacts.OppContact",
    related_name='external_records',
    null=True,
    blank=True,
    on_delete=models.CASCADE
)

external_record_id = models.CharField(
    max_length=1000
) 
and so on...

When I view the OppContact model either by viewing in the django admin screen or with OppContact.objects.all(), I see that the model has a field for "id". When I rollback to the migration before applying the oppcontact field, everything returns to work as normal, meaning I can query/view ExternalRecords without getting an error.

This is my OppContact model:

class OppContact(UUIDPrimaryKey):
company = models.ForeignKey(
    "accounts.Company",
    on_delete=models.CASCADE,
    blank=True,
    null=True
)

first_name = models.CharField(
    max_length=100
)

last_name = models.CharField(
    max_length=100
)...

And this is another model to which my ExternalRecord can be linked, Institution:

class Institution(UUIDPrimaryKey, CreatedModifiedMixin, models.Model):
company = models.ForeignKey(
    "accounts.Company",
    related_name='institutions',
    null=False,
    blank=False,
    on_delete=models.CASCADE,
)

owner = models.ForeignKey(
    "accounts.EmailUser",
    related_name='institutions',
    null=True,
    blank=True,
    on_delete=models.CASCADE,
)

name = models.CharField(max_length=100, null=False, blank=False)....

The only difference I see between the models is the OppContact doesn't have the CreatedModifiedMixin or models.Model, but I thought UUIDPrimaryKey extended models.Model, so I didn't think it mattered.

I have been stuck on this for several days, so any pointers in the right direction would be helpful (: Thank you all!

0 Answers
Related