from south.db import db 被 django 1.7+ 中的什么替换了?
from south.db import db replaced by what in django 1.7+?
我正在使用 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()
据我了解,替换为:
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)
我正在使用 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()
据我了解,替换为:
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)