[英]Django migrations not detecting unique=True change
I am getting the following error after trying to add a foreignkey from CrackingJob.hash_mode_numeric
to HashMappings
. 我试图从添加外键后收到以下错误CrackingJob.hash_mode_numeric
到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. 最初,我试图将FK直接设置为HashMappings.hash_mode_numeric
而没有唯一约束,并且正确地给出了错误,但是在添加unique=True
我仍然收到错误。 Even when i try to just use the PK (auto generated unique id) as FK, like in the code below. 即使当我尝试仅将PK(自动生成的唯一ID)用作FK时,如下面的代码所示。
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)
尝试清除hashmappings表中的数据,然后运行migration命令-> python manage.py migration
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.