å¤é¨ãã¼ã¨ãã¦åç §ããã¦ããåã«auto_incrementãã¤ãå¿ããå ´å
MariaDB 10.1
åå¿é²ãã¡ã¢
æ§ç¯æ¸ã¿ã®ãã¼ãã«ã®ä¸»ãã¼åã«AUTO_INCREMENTãã¤ãå¿ãã¦ãããªã©ã®çç±ã«ãããå¾ããAUTO_INCREMENTãä»ä¸ãããã¨ããã
ãã®åãä»ã®ãã¼ãã«ããå¤é¨ãã¼å¶ç´ã§åç
§ããã¦ããã¨ãåç´ã«ALTER TABLEãããã¨ãã¦ã以ä¸ã®ãããªã¨ã©ã¼ãçºçããã
ERROR 1833 (HY000): Cannot change column 'person_id': used in a foreign key constraint 'child1_fk1' of table 'mydb.child1'
ã解決çã
- é¢é£ãããã¼ãã«ããã¹ã¦WRITEããã¯ãã
- åãã¼ãã«ã®å¤é¨ãã¼å¶ç´ãä¸æçã«åé¤ãã
- ALTER TABLEã§è¦ªãã¼ãã«ã®åã«AUTO_INCREMENTãã¤ãã
- å¤é¨ãã¼å¶ç´ãæ»ãï¼åãã¼ãã«ã«ããä¸åº¦å¤é¨ãã¼å¶ç´ãã¤ããï¼
- ãã¼ãã«ãã¢ã³ããã¯ãã
lock tables parent write, child1 write, child2 write, child3 write; alter table child1 drop foreign key child1_fk1; alter table child2 drop foreign key child2_fk1; alter table child3 drop foreign key child3_fk1; alter table parent modify person_id int auto_increment; alter table child1 add foreign key(child1_fk1) references parent(person_id); alter table child2 add foreign key(child2_fk1) references parent(person_id); alter table child3 add foreign key(child3_fk1) references parent(person_id); unlock tables;
ãåèã
https://stackoverflow.com/questions/13606469/cannot-change-column-used-in-a-foreign-key-constraint