Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't alter table to remove auto_increment due to foreign keys

Tags:

mysql

I'm trying to remove Auto_Increment from the column _id in my MySQL database. However that column is the primary key for the table and when I'm using this command

ALTER TABLE Profile
MODIFY _id INT PRIMARY KEY NOT NULL

I get an error telling me that I can't do that since there are other tables which references the primary key.

My question is therefore: Is there a way to get around this problem?

like image 306
Michael Tot Korsgaard Avatar asked Jan 09 '23 03:01

Michael Tot Korsgaard


1 Answers

the easiest and fastest way is the following:

set foreign_key_checks = 0;
alter table Profile change column _id _id INT NOT NULL;
set foreign_key_checks = 1;

found here

like image 161
Pontios Avatar answered Jan 31 '23 02:01

Pontios