[Python] Column Foreign key is of type bigint but expression is of type uuid in Django

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I want to use UUIDField for primary key. This is my model:

    class Organization(models.Model):
    id = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False)
    name = models.CharField(max_length=124)


    All things is good. But when I want to use id of Organization model for ForeignKey in this model:

    class Member(models.Model):
    reference = models.ForeignKey('Organization', null=True, on_delete=models.PROTECT)
    name = models.CharField(max_length=124)


    I got this error:

    django.db.utils.ProgrammingError: column "reference" is of type bigint but expression is of type uuid
    LINE 1: "reference" = 'af104709-...
    ^
    HINT: You will need to rewrite or cast the expression.


    What can I do?

    Continue reading...

Compartilhe esta Página