【问题标题】:from south.db import db replaced by what in django 1.7+?从 south.db 导入 db 替换为 django 1.7+ 中的什么?
【发布时间】:2015-01-19 20:44:59
【问题描述】:
我正在修改其他人的代码以使用 django 1.8 运行,我想知道是否可以直接替换该行
from south.db import db
用途包括:
if db.backend_name == "postgres":
db.start_transaction()
db.execute_many(commands.PG_DISABLE_TRIGGERS)
db.commit_transaction()
【问题讨论】:
标签:
django
django-south
django-1.7
【解决方案1】:
据我了解,替换为:
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)