我使用django-pyodbc-azure
2.1.0.0 与运行良好的 Azure SQL 数据库连接。
当我正确理解文档时django-pyodbc-azure
,应该支持交易。
但是,此代码会立即更新该行。我希望,该行会在 20 秒后更新。
from django.db import transaction
from myapp.models import MyModel
import time
with transaction.atomic():
MyModel.objects.filter(id=1).update(my_field='Test')
time.sleep(20)
难道我做错了什么?我是否需要在 Azure SQL 数据库上指定某些设置?
当我AUTOCOMMIT = False
在我的数据库设置中进行设置时,以下代码根本不会更新该行。
MyModel.objects.filter(id=1).update(my_field='Test')
time.sleep(20)
transaction.commit()
我现在的settings.py
'azure_reporting': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'reporting_db',
'HOST': 'xxxxxx.database.windows.net',
'PORT': '',
'USER': 'xxxx@xxxxxx.database.windows.net',
'PASSWORD': 'xxxxxx',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server'
}
}