Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 909661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:55:03+00:00 2026-05-15T16:55:03+00:00

Background : Running a PostgreSQL database for a Django app (Django 1.1.1, Python2.4, psycopg2

  • 0

Background: Running a PostgreSQL database for a Django app (Django 1.1.1, Python2.4, psycopg2 and Postgres 8.1) I’ve restored the database from a SQL dump several times. Each time I do that and then try to add a new row, either shell, admin, or site front end, I get this error:

IntegrityError: duplicate key violates unique constraint "app_model_pkey"

The data dump is fine and is resetting the sequences. But if I try adding the row again, it’s successful! So I can just try jamming a new row into every table and then everything seems to be copacetic.

Question: Given that (1) the SQL dump is good and Postgres is reading it in correctly (per earlier question), and (2) Django’s ORM does not seem to be failing systemically getting next values, what is going on in this specific instance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:55:04+00:00Added an answer on May 15, 2026 at 4:55 pm

    Django doesn’t hold or directly read the sequence values in any way. I’ve explained it f.ex. in this question: 2088210/django-object-creation-and-postgres-sequences.

    Postgresql does increment the sequence when you try to add a row, even if the result of the operation is not successful (raises a duplicate key error) the sequence incrementation doesn’t rollback. So, that’s the reason why it works the second time you try adding a row.

    I don’t know why your sequences are not set properly, could you check what is the sequence value before dump and after restore, and do the same with the max() pk of the table? Maybe it’s an 8.1 bug with the restore? I don’t know. What I’m sure of: it’s not Django’s fault.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm working a project which uses Django with a Postgres database. We're also
I have a TableModel that is populated from a background running thread. I am
My app is a background service running in the foreground. In low memory situations
I want to trigger a long running background process (coded as a service) from
I have a background worker running to copy a huge file (several GBs) and
BACKGROUND: In running my app through a profiler, it looks like the hotspots are
I have several background tasks running on my Glassfish server implemented by @TimerService instances.
I want to list all background running processes and get details of those from
I Have a app running background. I use it to get the url on
I want to start a potentially long running background process from Delphi. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.