获取'DatabaseError'对象在DJango中没有属性'message'

Cas*_*ils 6 database django

我正在尝试在此处运行以下代码以将信息保存到数据库。我已经看到其他消息 - 但是 - 似乎这些解决方案适用于旧版本Python/DJango(因为它们似乎不适用于我现在使用的版本:Python 3.6.3DJango 1.11.7

if form.is_valid():
    try:
        item = form.save(commit=False)
        item.tenantid = tenantid
        item.save()
        message = 'saving data was successful'
    except DatabaseError as e:
        message = 'Database Error: ' + str(e.message)
Run Code Online (Sandbox Code Playgroud)

这样做时,我收到一条错误消息,如下所列的错误消息。我该如何解决这个问题,以便我可以打印出在 DB 级别找到的消息?

'DatabaseError' object has no attribute 'message'
Request Method:
POST
Request URL:
http://127.0.0.1:8000/storeowner/edit/
Django Version:
1.11.7
Exception Type:
AttributeError
Exception Value:
'DatabaseError' object has no attribute 'message'
Exception Location:
C:\WORK\AppPython\ContractorsClubSubModuleDEVELOP\libmstr\storeowner\views.py in edit_basic_info, line 40
Python Executable:
C:\WORK\Software\Python64bitv3.6\python.exe
Python Version:
3.6.3
Python Path:
['C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP',
 'C:\\WORK\\Software\\OracleInstantClient64Bit\\instantclient_12_2',
 'C:\\WORK\\Software\\Python64bitv3.6\\python36.zip',
 'C:\\WORK\\Software\\Python64bitv3.6\\DLLs',
 'C:\\WORK\\Software\\Python64bitv3.6\\lib',
 'C:\\WORK\\Software\\Python64bitv3.6',
 'C:\\Users\\dgmufasa\\AppData\\Roaming\\Python\\Python36\\site-packages',
 'C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP\\libintgr',
 'C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP\\libmstr',
 'C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP\\libtrans',
 'C:\\WORK\\AppPython\\ContractorsClubBackofficeCode\\libintgr',
 'C:\\WORK\\AppPython\\ContractorsClubBackofficeCode\\libmstr',
 'C:\\WORK\\TRASH\\tempforcustomer\\tempforcustomer\\libtempmstr',
 'C:\\WORK\\AppPython\\ContractorsClubBackofficeCode\\libtrans',
 'C:\\WORK\\Software\\Python64bitv3.6\\lib\\site-packages',
 'C:\\WORK\\Software\\Python64bitv3.6\\lib\\site-packages\\django-1.11.7-py3.6.egg',
 'C:\\WORK\\Software\\Python64bitv3.6\\lib\\site-packages\\pytz-2017.3-py3.6.egg']
Server time:
Sat, 9 Dec 2017 08:42:49 +0000
Run Code Online (Sandbox Code Playgroud)