I am getting the following error after trying to add a foreignkey from CrackingJob.hash_mode_numeric
to HashMappings
.
Initially i was trying to set the FK directly to HashMappings.hash_mode_numeric
without the unique constraint and it rightly gave the error, but after adding unique=True
i still get the error. Even when i try to just use the PK (auto generated unique id) as FK, like in the code below.
django.db.utils.ProgrammingError: there is no unique constraint
matching given keys for referenced table "appname_hashmappings"
Relevant code:
class HashMappings(models.Model):
hash_name = models.CharField(max_length=255, unique=True)
hash_mode_numeric = models.IntegerField(unique=True)
example_hash = models.TextField(max_length=2500)
supported = models.BooleanField(default=0)
class Meta:
ordering = ['hash_name']
def __str__(self):
return f'{self.hash_name}'
class CrackingJob(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL)
description = models.CharField(max_length=255)
hash_mode_numeric = models.ForeignKey(HashMappings, on_delete=models.CASCADE)