MySQL Forums
Forum List  »  InnoDB

set foreign_key_checks = 0; only kinda works
Posted by: Rico dos Santos
Date: December 17, 2008 02:03PM

I have a primary key for a table that was not set as unsigned. I want to add that attribute but there are a few other tables that have fks to this pk. Since the attributes of the pk has to match the attributes of the fks i can not add the unsigned attribute to any of them.

So, I did some research and tried "set foreign_key_checks = 0;". After I run this I can add fks to pks that do not exist. I can break the foreign key constraints as much as i want as far as setting the fk field = values that do not exist. For example i can set the fk = 10000000 but the pks only go up to 3000.

The problem is when I try to add the unsigned attribute to either the pk or any one of the fks. I get "1025 error on rename or ... to ... (errno150)". errno 150 is fk constraints. When i run "show innodb status;" and check the latest foreign key error i get

"LATEST FOREIGN KEY ERROR
------------------------
081217 14:41:41 Error in foreign key constraint of table a_db/a_table:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match to the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
CONSTRAINT a_table_ibfk_2 FOREIGN KEY (contactID) REFERENCES another_table (Id)
"

How can i get an error about an fk constraint if i just turned them off? I can assign fks that don't exist, and break fk constraints that way, but I can not add attributes that break the fk constraints?

I know that I could run a "show create table table_name;" and then drop the foreign key constrains, add my attribute, and add the constraints back. Worst comes to worst, Ill do just that but either I don't understand what foreign_key_checks does or there is a bug.

Thanks for any help,

Rico

Options: ReplyQuote


Subject
Views
Written By
Posted
set foreign_key_checks = 0; only kinda works
19287
December 17, 2008 02:03PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.