Login

Run sqlsequencereset on all apps

Author:
zbyte64
Posted:
June 19, 2012
Language:
Python
Version:
Not specified
Tags:
sqlsequencereset
Score:
2 (after 2 ratings)

Run this code in the python shell and sqlsequencereset will be executed for every app that has models.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import os

os.environ['DJANGO_COLORS'] = 'nocolor'

from django.core.management import call_command
from django.conf import settings
from django.db import connection
from django.db.models.loading import get_app
from StringIO import StringIO

commands = StringIO()
cursor = connection.cursor()

for app in settings.INSTALLED_APPS:
    label = app.split('.')[-1]
    if get_app(label, emptyOK=True):
        call_command('sqlsequencereset', label, stdout=commands)

cursor.execute(commands.getvalue())

More like this

  1. Serialize a model instance by chriswedgwood 1 week, 5 days ago
  2. Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 9 months, 2 weeks ago
  3. Crispy Form by sourabhsinha396 10 months, 1 week ago
  4. ReadOnlySelect by mkoistinen 10 months, 2 weeks ago
  5. Verify events sent to your webhook endpoints by santos22 11 months, 2 weeks ago

Comments

cericoda (on September 18, 2019):

also see https://gist.github.com/diegolopmon/e0d376fa46995b2b433e for more recent version

#

Please login first before commenting.