I'm running a script from inside a django application at the very root of the app_name folder; as in app_name>app_name.
At the top of the script I have this:
import os
import sys
os.environ.setdefault('DJANGO_SETTINGS_MODULE','versal.settings')
import django
django.setup()
I'm trying to handle an integrity error - my slugs need to be unique, so when one isn't unique, I want to handle the integrity error by adding a '1' to the slug.
try:
podcast_instance.slug = slugify(parsed_podcast.title)
podcast_instance.save()
podcast_saves += 1
except IntegrityError:
podcast_instance.slug = slugify(parsed_podcast.title + '1')
podcast_instance.save()
podcast_saves += 1
When I run this code, I get this:
Traceback (most recent call last):
File "podcasts.py", line 166, in <module>
podcasty()
File "podcasts.py", line 159, in podcasty
submit(podcast_objects,podcast_rss)
File "podcasts.py", line 73, in submit
except IntegrityError as e:
NameError: name 'IntegrityError' is not defined
You need to import it before using it.
from django.db import IntegrityError
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With