1
Try and insert data using the error handle mechanism:-
from django.db.utils import DatabaseError,IntegrityError
Then do something like this to prevent your python script to stop :-
try:
#write code to execute query here
except IntegrityError:
#write code to handle exception here(example creating a log)
Source:stackexchange.com