外鍵操作語句-Mysql

外鍵操作語句-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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章