[Answered ]-Django – Isn't there a way to connect a foreign key to a primary key of which datatype isn't integer?

2👍

You can use to_field , email must be unique=True:

class Commentor(models.Model):
    email = models.CharField(max_length=100, blank=False, null=False, primary_key=True, unique=True)
    ...

class Comments(models.Model):
    ...
    commentor = models.ForeignKey(Commentor, to_field='email')

Leave a comment