Reputation:
I have a table called "Address" it reference to the table "Member", Address has a column called "id" , this column is a foreignkey. I forgot to add a autoincroment on this column.
Member:
Address:
when i try in sql
ALTER TABLE Address MODIFY COLUMN id INT auto_increment;
it throughs an error:
Error Code: 1833. Cannot change column 'id': used in a foreign key constraint 'fk_Member_Address1' of table 'mydb.member'
Upvotes: 0
Views: 1705
Reputation: 1181
Try to fire these queries in sequence:
ALTER TABLE Member DROP FOREIGN KEY
address_id
;
ALTER TABLE Address MODIFY COLUMN id INT auto_increment;
ALTER TABLE Member ADD FOREIGN KEY (
address_id) REFERENCES Address(
id);
Here you first remove foreign key constraint from member table, then add auto_increment to address table and then again add foreign key constraint to member table.
Hope it helps.
Upvotes: 0
Reputation: 179
Firstly, you have to drop the foreign key constraint Then change the name and recreate the constraint.
Upvotes: 0