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 9166687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:12:31+00:00 2026-06-17T15:12:31+00:00

I’m adding South to an existing application which has many installations however I don’t

  • 0

I’m adding South to an existing application which has many installations however I don’t have access to production environments due to security reasons.
We can only supply Python installation script that will be run by persons that often don’t have any knowledge about Django, South, etc.

I’m aware of the fact that for existing installations any future upgrade will have to start with executing:

manage.py syncdb
manage.py migrate --all 0001 --fake

and any new installations will start with:

manage.py syncdb
manage.py migrate -all

Is there any way to detect if south initial migrations were already applied (e.g. by detecting if south_migfationhistory table exists) in a database agnostic way (perhaps with Django itself) ?
What I would like to do is:

(pseudocode)
db = database.connect(dbname, user, password)
if db.table_existst('south_migrationhistory'):
  execute 'manage.py syncdb'
  execute 'manage.py migrate --all'
else:
  execute 'manage.py syncdb'
  execute 'manage.py migrate --all 0001 --fake'
  execute 'manage.py migrate --all'
  • 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-06-17T15:12:32+00:00Added an answer on June 17, 2026 at 3:12 pm

    For future reference this is how I ended up doing this:

    if args.settings_dir not in sys.path:
      sys.path.append(args.settings_dir)
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    
    #try to query db for existing objects, e.g. user groups
    #in order to detect if we are upgrading an existing installation
    from django.db.utils import DatabaseError
    try:
      from django.contrib.auth.models import Group
      tmp = len(Group.objects.all()) #evaluate to force db query
      updating = True
    except DatabaseError as e:
      updating = False
    
    #try to query db for South migrations in order to detect if South was already applied
    #in this installation (if not then accessing MigrationHistory will throw an excepion)
    try:
      from south.models import MigrationHistory
      has_south = bool(len(MigrationHistory.objects.all()))
    except ImportError as e:
      print 'ERROR: Error importing South migration history: ' + str(e)
      print 'Exiting'
      exit(1)
    except DatabaseError as e:
      has_south = False
    
    #syncdb to create south_migrationhistory table, portal models will not be synced
    from django.core.management import execute_from_command_line
    argv = ['manage.py', 'syncdb', '--settings=settings', '--pythonpath=' + args.settings_dir]
    execute_from_command_line(argv)
    
    #if we are updating existing installation and South wasn't already applied
    #then initial migration has to be 'faked' in order to sync with existing tables
    if updating and not has_south:
      print 'INFO: Faking initial database migration...'
      argv = ['manage.py', 'migrate', '--all', '0001', '--fake',
              '--settings=settings', '--pythonpath=' + args.settings_dir]
      execute_from_command_line(argv)
    
    #run normal migrations
    print 'INFO: Applying database migrations...'
    argv = ['manage.py', 'migrate', '--all',
            '--settings=settings', '--pythonpath=' + args.settings_dir]
    execute_from_command_line(argv)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which has BIG numbers and small numbers in it. I
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.