从south.db导入db替换为django 1.7+中的内容?

时间:2015-01-19 20:45:00

标签: django django-south django-1.7

我正在修改其他人使用django 1.8运行的代码,我想知道是否有直接替换该行

 from south.db import db

使用include:

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

1 个答案:

答案 0 :(得分:2)

据我了解,替换是:

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

用途:

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

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

cursor = connection.cursor() 
with transaction.atomic():
    cursor.executemany(commands.PG_DISABLE_TRIGGERS)