外鍵操作語句-Mysql
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'UK_j5c8ny79k6s3xessw0f57r1al'
解決思路:刪除關聯表對應的索引:
show index from dbmt.user_role_mapping;
DROP INDEX UK_j5c8ny79k6s3xessw0f57r1al ON dbmt.user_role_mapping;
查看外鍵:
show create table user_role_mapping;
刪除外鍵:
alter table user_role_mapping drop foreign key user_role_mapping_ibfk_1;
alter table role_permission_mapping drop foreign key role_permission_mapping_ibfk_1;
添加外鍵:
ALTER TABLE user_role_mapping ADD FOREIGN KEY (roleId) REFERENCES role(id);
ALTER TABLE role_permission_mapping ADD FOREIGN KEY (userId) REFERENCES user(id);