我不是MySQL专家,我不能完全弄清楚问题以及如何处理它;我尝试使用其他名称创建一个新数据库,但这没有发生.我认为这是我的Django项目创建的问题.
这是所有信息:
C:\Users...>python manage.py syncdbCreating tables ...Creating table auth_permissionCreating table auth_group_permissionsCreating table auth_groupCreating table auth_user_user_permissionsCreating table auth_user_groupsCreating table auth_userCreating table auth_messageCreating table django_content_typeCreating table django_sessionCreating table django_siteCreating table django_admin_logCreating table forum_categoryCreating table forum_threadCreating table forum_postYou just installed Django's auth system,which means you don't have any superusers defined.Would you like to create one Now? (yes/no): yesUser@R_502_6889@ (Leave blank to use 'me'): adminE-mail address: example@example.comPassword:Password (again):Superuser created successfully.Traceback (most recent call last): file "manage.py",line 14,in execute_manager(settings) file "C:\Python27\lib\site-packages\django\core\management\__init__.py",line 438,in execute_manager utility.execute() file "C:\Python27\lib\site-packages\django\core\management\__init__.py",line 379,in execute self.fetch_command(subcommand).run_from_argv(self.argv) file "C:\Python27\lib\site-packages\django\core\management\base.py",line 191,in run_from_argv self.execute(*args,**options.__dict__) file "C:\Python27\lib\site-packages\django\core\management\base.py",line 220,in execute output = self.handle(*args,**options) file "C:\Python27\lib\site-packages\django\core\management\base.py",line 351,in handle return self.handle_noargs(**options) file "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py",line 109,in handle_noargs emit_post_sync_signal(created_models,verbosity,interactive,db) file "C:\Python27\lib\site-packages\django\core\management\sql.py",line 190,in emit_post_sync_signal interactive=interactive,db=db) file "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py",line 172,in send response = receiver(signal=self,sender=sender,**@R_502_6889@d) file "C:\Python27\lib\site-packages\django\contrib\auth\management\__init__.p ",line 51,in create_permissions content_type=ctype file "C:\Python27\lib\site-packages\django\db\models\manager.py",line 138,in create return self.get_query_set().create(**kwargs) file "C:\Python27\lib\site-packages\django\db\models\query.py",line 360,in create obj.save(force_insert=True,using=self.db) file "C:\Python27\lib\site-packages\django\db\models\base.py",line 460,in save self.save_base(using=using,force_insert=force_insert,force_update=force_update) file "C:\Python27\lib\site-packages\django\db\models\base.py",line 553,in save_base result = manager._insert(values,return_ID=update_pk,using=using) file "C:\Python27\lib\site-packages\django\db\models\manager.py",line 195,in _insert return insert_query(self.model,values,**kwargs) file "C:\Python27\lib\site-packages\django\db\models\query.py",line 1436,in insert_query return query.get_compiler(using=using).execute_sql(return_ID) file "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py",line 791,in execute_sql cursor = super(sqlInsertCompiler,self).execute_sql(None) file "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py",line 735,in execute_sql cursor.execute(sql,params) file "C:\Python27\lib\site-packages\django\db\backends\util.py",line 34,in execute return self.cursor.execute(sql,params) file "C:\Python27\lib\site-packages\django\db\backends\MysqL\base.py",line 86,in execute return self.cursor.execute(query,args) file "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\MysqLdb\cursors.py",line 174,in execute self.errorhandler(self,exc,value) file "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\MysqLdb\connections.py",line 36,in defaulterrorhandler raise errorclass,errorvaluedjango.db.utils.IntegrityError: (1062,"Duplicate entry '9-delete_category' for key 'content_type_ID'")
#models.pyfrom django.db import modelsfrom django.contrib.auth.models import Userclass category(models.Model): Title = models.CharFIEld(max_length=80) class Meta: verbose_@R_502_6889@_plural = "categorIEs" permissions = ( ("create_category","Can create new categorIEs"),("edit_category","Can edit the Titles of categorIEs"),("delete_category","Can delete a category"),("merge_category","Can merge multiple categorIEs together"),)class Thread(models.Model): creation_date = models.DateTimeFIEld() author = models.ForeignKey(User) Title = models.CharFIEld(max_length=80) category = models.ForeignKey(category) class Meta: ordering = ["-creation_date"] permissions = ( ("create_thread","Create new threads"),("edit_thread","Edit thread Titles"),("delete_thread","Delete threads"),("merge_thread","Merge multiple threads together"),("lock_thread","Lock threads"),("unlock_thread","Open locked threads"),("ban_user_in_thread","Ban user from post in thread"),("timeout_user_in_thread","Ban user from posting in thread temporarily"),("appoint_threadmin","Give a user mod-like permissions in a thread"),)class Bookmark(models.Model): user = models.ForeignKey(User) thread = models.ForeignKey(Thread)class Subscription(models.Model): user = models.ForeignKey(User) thread = models.ForeignKey(Thread)class Post(models.Model): creation_date = models.DateTimeFIEld() author = models.ForeignKey(User) thread = models.ForeignKey(Thread) content = models.TextFIEld() class Meta: ordering = ["creation_date"] permissions = ( ("create_post","Can create new post"),("edit_post","Can edit all users' posts"),("delete_post","Can delete posts"),)
+----------------------------+| tables_in_mydb |+----------------------------+| auth_group || auth_group_permissions || auth_message || auth_permission || auth_user || auth_user_groups || auth_user_user_permissions || django_admin_log || django_content_type || django_session || django_site || forum_bookmark || forum_category || forum_post || forum_subscription || forum_thread |+----------------------------+MysqL> select * from django_content_type;+----+--------------+--------------+--------------+| ID | @R_502_6889@ | app_label | model |+----+--------------+--------------+--------------+| 1 | permission | auth | permission || 2 | group | auth | group || 3 | user | auth | user || 4 | message | auth | message || 5 | content type | ContentTypes | ContentType || 6 | session | sessions | session || 7 | site | sites | site || 8 | log entry | admin | logentry || 9 | category | forum | category || 10 | thread | forum | thread || 11 | bookmark | forum | bookmark || 12 | subscription | forum | subscription || 13 | post | forum | post |+----+--------------+--------------+--------------+解决方法 Django每个模型自动 creates few default permissions,这些是:添加,删除和更改.您正在尝试使用相同名称创建权限,从而获得完整性错误.只需删除元描述中的删除_ ***,一切都应该没问题. 总结
以上是内存溢出为你收集整理的python – IntegrityError:(1062,密钥重复项)全部内容,希望文章能够帮你解决python – IntegrityError:(1062,密钥重复项)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)