I would like to add the autoincrement
property for all my table's columns
named id
in a schema
. However, most of them are part of a foreign key
constraint. Is there any other way to do it without dropping
the foreign key constraint for all of them, adding
the autoincrement
property and re-creating
the foreign key
constraints?
Thank you very much!
Best Answer
Try temporary disabling foreign keys (make sure no ones allowed to update the db meanwhile):
Note that
set foreign_key_checks = 1;
does not validate foreign keys, so if someone manages to add invalid values whilst foreign keys are disables, you end up with an inconsistent db:I vaguely remember that this was also the case when adding foreign keys, but this bug seems to have been fixed since: