I was trying to add a check constraint to my create table DDL in the following manner:
CREATE TABLE TYPE_SCENE
(
ID_TYPE_SCENE INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
ID_TYPE INTEGER(10) NOT NULL,
CREATED_BY VARCHAR(20) NOT NULL,
CREATED_ON TIMESTAMP NOT NULL,
COMPLETE_SCENE CHAR(1),
INCOMPLETE_SCENE CHAR(1),
AMENDED_BY VARCHAR(20),
AMENDED_ON TIMESTAMP,
CONSTRAINT FK_TYPE FOREIGN KEY (ID_TYPE) REFERENCES TYPE_DATA(ID_TYPE),
CONSTRAINT COMPLETE_SCENE_CHECK CHECK (COMPLETE_SCENE IN ( 'M', 'N', 'O' )),
CONSTRAINT INCOMPLETE_SCENE_CHECK CHECK (INCOMPLETE_SCENE IN ( 'A', 'B', 'C' ))
)
However when I run this query in MySQL workbench, I get the following error: Error Code: 1215. Cannot add foreign key constraint
I know the problem is because of the CHECK constraint as the query gives me a syntax error pointing at the CHECK constraints. What am I doing wrong? I thought this was the way to implement CHECK constraints. Why does it say foreign key constraint problem?
Funny thing is it used to work on MySQL 5.1 before I upgraded to MySQL 5.6.
I read a few forums and questions where it says MySQL does not support this anymore and use triggers. However it used to work with earlier MySQL versions. Secondly, I should still be able to execute the query as the problem is that the constraint does not work in MySQL, however it never was a syntax issue.
Any ideas?
Thanks!