Friday, July 22, 2011

MySQL ERROR 1005 (HY000): Can't create table

Below is the table def that caused the problem:

CREATE  TABLE IF NOT EXISTS `T_ABC` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `source_col` int NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_src_col` (`source_col` ASC) ,
  CONSTRAINT `fk_src_col`
    FOREIGN KEY (`source_col` )
    REFERENCES `parent_table` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

and on execution it was giving the error ERROR 1005 (HY000): Can't create table schema.T_ABC.frm

The fix to issue is: that parent_table.id is of bigint type, while this table foreign key is only int; when i changed the source_col from int to big_int things went well.

hope this helps somebody.

No comments:

Post a Comment