Calvin Cheng
Calvin Cheng

Reputation: 36506

django: duplicate key value violates unique constraint

 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:-

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?

Upvotes: 1

Views: 1438

Answers (1)

Calvin Cheng
Calvin Cheng

Reputation: 36506

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.

Upvotes: 1

Related Questions