Skip to content
Advertisement

Add auto_increment feature to a primary key

I have a problem related to sql language. I am trying to add the auto_increment features to a pre-existing row with the primary key attribute. What I get back is :

Error Code: 1833. Cannot change column ‘ODB_ID’: used in a foreign key constraint target_ibfk of table ‘test3.target’.

The statement used for the table was

And this table refer to this one:

I have tried with the following commands plus from the MySQL gui:

I viewed another suggestion on the site, but it doesn’t work for me.

Thank you in advance.

Advertisement

Answer

You need to disable FOREIGN_KEY_CHECKS. Then enable it again after the operation. The following works for me:

See demo

Note that I also removed PRIMARY KEY after auto_increment, since ODB_ID is already the PRIMARY KEY.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement