Coder Social home page Coder Social logo

django-postgresql-fix-sequences's Introduction

django-postgresql-fix-sequences

Fixes sequences in postgresql to help prevent the duplicate primary key errors.

The command needs to be run with all other connections to the database closed, so that there is no competition for the access to the sequences.

Examples:

python manage.py postgres_fix_sequences --auto
python manage.py postgres_fix_sequences --minvalue 1 --increment 2
python manage.py postgres_fix_sequences --tables=auth_user --auto

The fixes can be applied either to all tables that are part of a django project, or to specifically selected tables, in which case those tables do not have to be part of any django application.

Sequences can be fixed either automatically (where appropriate) or by manually setting the sequence parameters (supported values are minvalue and increment - as defined in CREATE SEQUENCE postgresql command).

Fix sequences automatically with the --auto flag

Sequences will be repaired automatically. Use this if you know that this is possible and safe, e.g. that the starting value and the step of the sequences are correct, but the current value may be off.

Note that either --auto or --min-value together with --increment must be given.

The command takes current value in the sequence currval() and the next value netxval() and determines step in the sequence.

Finds the highest id number (let's call it max_id) for the rows matching the given sequence, if id number is greater or equals to what is returned by the nextval() we need to set the current value with setval() to exactly what we found for max_id.

Specify minimum value and the increment for the sequence

If you cannot use the --auto method, then you have to specify --minvalue and --increment for the sequence manually. Both should be positive integers.

Specify tables manually with --tables option

For example, with:

python manage.py postgres_fix_sequences --tables=auth_user,auth_group

only tables auth_user and auth_group will be fixed.

Note that with the --tables table names do not have to be part of a django project.

Copyright: 2012 Askbot SpA, Vina del Mar, Chile. Author: Evgeny Fadeev, [email protected] License: MIT

django-postgresql-fix-sequences's People

Contributors

evgenyfadeev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.