我试图进行初始迁移(制作一些默认表格)并且它会中断:
[...]
b"SELECT `django_content_type`.`id`, `django_content_type`.`name`,`django_content_type`.`app_label`, `django_content_type`.`model` FROM `django_content_type` WHERE (`django_content_type`.`model` = 'logentry' AND `django_content_type`.`app_label` = 'admin') LIMIT 21"
b'SET @@session.autocommit = OFF'
b"INSERT INTO `django_content_type` (`name`, `app_label`, `model`) VALUES ('log entry', 'admin', 'logentry')"
b'COMMIT'
b'SET @@session.autocommit = ON'
b'SELECT `auth_permission`.`content_type_id`, `auth_permission`.`codename` FROM `auth_permission` INNER JOIN `django_content_type` ON ( `auth_permission`.`content_type_id` = `django_content_type`.`id` ) WHERE `auth_permission`.`content_type_id` IN (1) ORDER BY `django_content_type`.`app_label` ASC, `django_content_type`.`model` ASC, `auth_permission`.`codename` ASC'
b'SET @@session.autocommit = OFF'
b"INSERT INTO `auth_permission` (`name`, `content_type_id`, `codename`) VALUES ('Can add log entry', 1, 'add_logentry'), ('Can change log entry', 1, 'change_logentry'), ('Can delete log entry', 1, 'delete_logentry')"
b'COMMIT'
b'SET @@session.autocommit = ON'
b"SELECT `django_content_type`.`id`, `django_content_type`.`name`, `django_content_type`.`app_label`, `django_content_type`.`model` FROM `django_content_type` WHERE `django_content_type`.`app_label` = 'admin' ORDER BY `django_content_type`.`name` ASC"
b'SET @@session.autocommit = OFF'
b"INSERT INTO `django_content_type` (`name`, `app_label`, `model`) VALUES ('log entry', 'admin', 'logentry')"
b'ROLLBACK'
b'SET @@session.autocommit = ON'
我有一个例外:
[...]
django.db.utils.IntegrityError: Duplicate entry 'admin-logentry' for key 'django_content_type_app_label_3ec8c61c_uniq'
[...]
它试图将同一行添加两次,但为什么?
从我的settings.py安装了应用
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
和db:
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': '###',
'HOST': '/var/run/mysqld/mysqld.sock',
'USER': '###',
'PASSWORD': '###'
},
django 1.7和python 3.2
(我通过修改文件/usr/local/lib/python3.2/dist-packages/mysql/connector/connection.py来打印sqls
编辑:
好吧,我通过将我的架构校对更改为" utf8 - 默认校对"来解决这个问题。可能有些django模块或连接器无法比较选择结果并试图插入相同的结果。
答案 0 :(得分:0)
名称是主键,您可以插入
"INSERT INTO `django_content_type` (`name`, `app_label`, `model`) VALUES ('log entry', 'admin', 'logentry')"
INSERT INTO `django_content_type` (`name`, `app_label`, `model`) VALUES ('log entry', 'admin', 'logentry')" b'COMMIT'
主键是相同的值。