2
You haven’t imported OperationalError
before using it in your code:
from django.db import OperationalError
You might actually want to catch DatabaseError
instead of OperationalError
(which is a subclass of DatabaseError
).
Source:stackexchange.com