Skip to content

duplicate key value violates unique constraint "django_site_pkey" #3506

Answered by browniebroke
lionelwust asked this question in Q&A
Discussion options

You must be logged in to vote

when trying to do that

Can you expand a bit on how you're creating this? What have you tried, etc... Is it through the admin, a migration or via the Django console?

Here is how the original site is created:

Site.objects.update_or_create(
id=settings.SITE_ID,
defaults={
"domain": "{{cookiecutter.domain_name}}",
"name": "{{cookiecutter.project_name}}",
},
)

As you can see, we providing the ID primary key explicitly. I think it's a common issue with Django where the database sequen…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by browniebroke
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants