python – django.db.utils.IntegrityError:重复键值违反唯一约束“auth_permission_pkey”

python – django.db.utils.IntegrityError:重复键值违反唯一约束“auth_permission_pkey”,第1张

概述卡住我有一个数据库,当我尝试使 python manage.py迁移时,它会给出如下错误: django.db.utils.IntegrityError: duplicate key value violates unique constraint "auth_permission_pkey"DETAIL: Key (id)=(241) already exists. 以下是完整错误: Ope 卡住我有一个数据库,当我尝试使 python manage.py迁移时,它会给出如下错误:

django.db.utils.IntegrityError: duplicate key value violates unique constraint "auth_permission_pkey"DETAIL:  Key (ID)=(241) already exists.

以下是完整错误:

Operations to perform:  Apply all migrations: admin,auth,companyapp,ContentTypes,djcelery,kombu_transport_django,loginapp,projectmanagement,recruitmentproject,sessions,smallprojectRunning migrations:  No migrations to apply.Traceback (most recent call last):  file "manage.py",line 10,in <module>    execute_from_command_line(sys.argv)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/__init__.py",line 363,in execute_from_command_line    utility.execute()  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/__init__.py",line 355,in execute    self.fetch_command(subcommand).run_from_argv(self.argv)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/base.py",line 283,in run_from_argv    self.execute(*args,**cmd_options)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/base.py",line 330,in execute    output = self.handle(*args,**options)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/commands/migrate.py",line 227,in handle    self.verbosity,self.interactive,connection.alias,apps=post_migrate_apps,plan=plan,file "/home/ubuntu/.local/lib/python2.7/site-packages/django/core/management/sql.py",line 53,in emit_post_migrate_signal    **kwargs  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/dispatch/dispatcher.py",line 193,in send    for receiver in self._live_receivers(sender)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",line 83,in create_permissions    Permission.objects.using(using).bulk_create(perms)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/db/models/query.py",line 443,in bulk_create    IDs = self._batched_insert(obJs_without_pk,fIElds,batch_size)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/db/models/query.py",line 1080,in _batched_insert    inserted_ID = self._insert(item,fIElds=fIElds,using=self.db,return_ID=True)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/db/models/query.py",line 1063,in _insert    return query.get_compiler(using=using).execute_sql(return_ID)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",line 1099,in execute_sql    cursor.execute(sql,params)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/db/backends/utils.py",line 80,in execute    return super(CursorDeBUGWrapper,self).execute(sql,line 65,in execute    return self.cursor.execute(sql,params)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/db/utils.py",line 94,in __exit__    six.reraise(dj_exc_type,dj_exc_value,traceback)  file "/home/ubuntu/.local/lib/python2.7/site-packages/django/db/backends/utils.py",params)django.db.utils.IntegrityError: duplicate key value violates unique constraint "auth_permission_pkey"DETAIL:  Key (ID)=(241) already exists.
解决方法 没有太多其他上下文,看起来您已经为模型添加了一个唯一约束,但是数据库中的行违反了此约束,因此迁移失败.因此,在您的数据库中,您有两行,其中auth_permission_pkey == 241.

您需要删除或更改此行,使其唯一,然后重新运行迁移.

总结

以上是内存溢出为你收集整理的python – django.db.utils.IntegrityError:重复键值违反唯一约束“auth_permission_pkey”全部内容,希望文章能够帮你解决python – django.db.utils.IntegrityError:重复键值违反唯一约束“auth_permission_pkey”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/1196379.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存