-4

I keep getting "Error 150" when trying to run this query:

CREATE TABLE `NewTable` (
`ID`  int NULL AUTO_INCREMENT ,
`Entry_ID`  int NULL ,
`Content`  varchar(255) NULL ,
`Type`  varchar(255) NULL ,
PRIMARY KEY (`ID`),
CONSTRAINT `Entry_ID` FOREIGN KEY (`Entry_ID`) REFERENCES `ENTRIES` (`EID`),
CONSTRAINT `Content` FOREIGN KEY (`Content`) REFERENCES `MEDIA` (`CONTENT`),
CONSTRAINT `Type` FOREIGN KEY (`Type`) REFERENCES `MEDIA` (`CONTENT_TYPE`)
)
;

I would appreciate any help, thanks!

john cs
  • 2,220
  • 5
  • 32
  • 50
  • MySQL error code 150: Foreign key constraint is incorrectly formed – Mitch Wheat May 29 '13 at 03:17
  • INNODB ?: http://stackoverflow.com/questions/160233/what-does-mysql-error-1025-hy000-error-on-rename-of-foo-errorno-150-me#179501 – Mitch Wheat May 29 '13 at 03:17
  • http://stackoverflow.com/questions/825362/mysql-error-150-foreign-keys – Nanda May 29 '13 at 03:17
  • `SHOW ENGINE INNODB STATUS` for more info on the cause; although, as an aside, perhaps `(Content, Type)` should be a composite foreign key? – eggyal May 29 '13 at 03:18

1 Answers1

0

This problem is causing due to following reason like

1) It must have the right column names and types.

2) It must have indexes on the referenced keys, as stated earlier.

If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

Both tables must be InnoDB tables and they must not be TEMPORARY tables.

see innodb-foreign-key-constraints

Rahul
  • 5,603
  • 6
  • 34
  • 57