简体   繁体   中英

Convert table engine MyISAM to INNODB errno: 150

I have this table :

CREATE TABLE IF NOT EXISTS `interlocuteur_fonction` (
  `id_interlocuteur_fonction` int(11) NOT NULL AUTO_INCREMENT,
  `id_interlocuteur` int(11) NOT NULL,
  `id_fonction_interlocuteur` int(11) NOT NULL,
  `defaut` varchar(1) NOT NULL,
  PRIMARY KEY (`id_interlocuteur_fonction`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2227 ;

When i try this query :

ALTER TABLE `interlocuteur_fonction` engine=InnoDB

I received an error message:

#1025 - Error on rename of './preprod_test/#sql-457_210' to './preprod_test/interlocuteur_fonction' (errno: 150)

Output of SHOW ENGINE INNODB STATUS:

LATEST FOREIGN KEY ERROR
------------------------
130328 12:00:36 Error in foreign key constraint of table 
ilang2_test/interlocuteur_fonction:
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 the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. 
Constraint:
,
CONSTRAINT "interlocuteur_fonction_id_interlocuteur_id_interlocuteur" FOREIGN KEY 
("id_interlocuteur") REFERENCES "interlocuteurs" ("id_interlocuteur")
InnoDB: Renaming table `preprod_test`.`#sql-457_1bb` to 
`preprod_test`.`interlocuteur_fonction` failed!

Any idea is highly appreciated. Thanks.

I encountered that error mostly when the column of the foreign key doesn't exactly match the column where it is pointing to. (Type, signed/unsigned)

EDIT After reading your post a second time, I recognized the real error: your interlocuteurs table needs an index with id_interlocuteur as first column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM