名称“IntegrityError”未定义为什么不能在此脚本上使用“except:IntegrityError”?

2024-10-02 02:41:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个django应用程序中运行一个脚本,它位于app_name文件夹的根目录下;就像在app_name>;app_name中一样。在

在脚本的顶部我有这样的内容:

import os
import sys
os.environ.setdefault('DJANGO_SETTINGS_MODULE','versal.settings')
import django
django.setup()

我试图处理一个完整性错误-我的slug需要是唯一的,所以当一个不唯一时,我想通过在slug中添加一个'1'来处理完整性错误。在

^{pr2}$

当我运行这段代码时,我得到:

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

Tags: djangonameinpyimport脚本appos

热门问题