MySQL “ERROR 1005 (HY000): Can't create table 'foo.#sql-12c_4' (errno: 150)”

后端 未结 14 787
情深已故
情深已故 2020-12-03 04:13

I was working on creating some tables in database foo, but every time I end up with errno 150 regarding the foreign key. Firstly, here\'s my code for creating t

14条回答
  •  离开以前
    2020-12-03 04:41

    Also both the tables need to have same character set.

    for e.g.

    CREATE TABLE1 (
      FIELD1 VARCHAR(100) NOT NULL PRIMARY KEY,
      FIELD2 VARCHAR(100) NOT NULL
    )ENGINE=INNODB CHARACTER SET utf8 COLLATE utf8_bin;
    

    to

    CREATE TABLE2 (
      Field3 varchar(64) NOT NULL PRIMARY KEY,
      Field4 varchar(64) NOT NULL,
      CONSTRAINT FORIGEN KEY (Field3) REFERENCES TABLE1(FIELD1)
    ) ENGINE=InnoDB;
    

    Will fail because they have different charsets. This is another subtle failure where mysql returns same error.

提交回复
热议问题