繁体   English   中英

Django迁移未检测到unique = True更改

[英]Django migrations not detecting unique=True change

我试图从添加外键后收到以下错误CrackingJob.hash_mode_numericHashMappings

最初,我试图将FK直接设置为HashMappings.hash_mode_numeric而没有唯一约束,并且正确地给出了错误,但是在添加unique=True我仍然收到错误。 即使当我尝试仅将PK(自动生成的唯一ID)用作FK时,如下面的代码所示。

django.db.utils.ProgrammingError: there is no unique constraint
matching given keys for referenced table "appname_hashmappings"

相关代码:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM