django:重复键值违反唯一约束

时间:2023-01-10 23:06:39
 from django.contrib.auth import Group

 class Plan
    name = models.CharField(max_length=100, unique=True, null=False)
    description = models.TextField(blank=True)
    group = models.ForeignKey(Group, null=False, blank=False)

When I attempt to save a 2nd instance of plan in django admin, setting the group to the same group as the previous plan object that I saved, I get an error traceback:-

当我尝试在django admin中保存计划的第二个实例时,将该组设置为与我保存的上一个计划对象相同的组,我得到一个错误回溯: -

duplicate key value violates unique constraint "plans_plan_group_id_key"
DETAIL:  Key (group_id)=(1) already exists.

Why is that so and how do I allow many different plans to relate to the same group object?

为什么会这样,我如何允许许多不同的计划与同一组对象相关?

1 个解决方案

#1


1  

This 3rd party app I am using some how fails to have a migration file that removes an originally specified unique=True. I added in a new south migration to force unique=False and all is fine and dandy now.

我正在使用的第三方应用程序如何无法获得删除最初指定的unique = True的迁移文件。我添加了一个新的南迁移强制唯一=假,现在一切都很好和花花公子。

#1


1  

This 3rd party app I am using some how fails to have a migration file that removes an originally specified unique=True. I added in a new south migration to force unique=False and all is fine and dandy now.

我正在使用的第三方应用程序如何无法获得删除最初指定的unique = True的迁移文件。我添加了一个新的南迁移强制唯一=假,现在一切都很好和花花公子。