django.db.utils.IntegrityError:submissionby_id列不是唯一的

时间:2017-11-06 09:10:28

标签: django model-view-controller

我很难解决这个错误。 这就是我的模型现在的样子。

class trendingideas(models.Model):
        submit = models.CharField(max_length=10)
        iname = models.CharField(max_length=15, unique = True)
        idea = models.TextField(unique = True)
        support = models.PositiveSmallIntegerField()
        submittedon = models.DateTimeField()
        readbyadmin = models.BooleanField()
        feasibilitycheck = models.BooleanField()

        def __str_(self):
                return str(self.iname)

class trendingidea_admin(admin.ModelAdmin):
        list_display = ('submit','iname','idea','support','submittedon','readbyadmin','feasibilitycheck')
上面定义的

提交之前定义为: submittedby = models.ForeignKey(User)

我做了一些更改,现在无论我做什么,我都会收到错误:

    return self.cursor.execute(sql, params)
  File "/usr/lib64/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: column submittedby_id is not unique.

如果我执行inspectdb,我会看到poblematic列(陈旧条目)

class HomeTrendingidea(models.Model):
    id = models.IntegerField(primary_key=True)  # AutoField?
    iname = models.CharField(unique=True, max_length=15)
    idea = models.TextField(unique=True)
    submittedon = models.DateField()
    support = models.PositiveSmallIntegerField()
    readbyadmin = models.BooleanField()
    feasibilitycheck = models.BooleanField()
    submittedby = models.ForeignKey(AuthUser, models.DO_NOTHING)
    assignedto = models.ForeignKey(AuthUser, models.DO_NOTHING, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'home_trendingidea'

我怎样才能让它恢复正常? 提前谢谢你。

0 个答案:

没有答案