Search code examples
djangodjango-southdjango-1.7

from south.db import db replaced by what in django 1.7+?


I'm amending someone else's code to run with django 1.8 and I wonder if there is a direct replacement for the line

 from south.db import db

uses include:

if db.backend_name == "postgres":
    db.start_transaction()
    db.execute_many(commands.PG_DISABLE_TRIGGERS)
    db.commit_transaction()

Solution

  • As far as I understand, the replacements are:

    from django.db import connection
    from django.db import transaction
    

    Usages:

    >>> from django.db import connection
    >>> connection.vendor
    u'postgresql'
    

    And:

    from django.db import connection
    from django.db import transaction
    
    cursor = connection.cursor() 
    with transaction.atomic():
        cursor.executemany(commands.PG_DISABLE_TRIGGERS)