This is my first time working on database, and I couldn't find a way out on this problem.
I was trying to add foreign key to one of columns in my table, but it gets
"ERROR 1215 : Cannot add foreign key constraint"
I googled this problem, but it was pretty hard to figure out what is wrong.
Here's what happened
I wanted my tables be like below
tableA
└ id - PRIMARY KEY
└ name
└ password
tableB
└ title
└ no - PRIMARY KEY
└ and so on... (plenty of more columns here) then!!
└ unique_id - PRIMARY KEY
(So, tableB has multiple primary keys)
tableC
└ id - References tableA (id) & PRIMARY KEY
└ no - References tableB (no) & PRIMARY KEY
└ memo
(So does tableC)
So I created columns like this, and I tried to set foreign keys in tableC
id column have gone well, but no column still returns error code I mentioned above, Error code 1215
.
I matched a data type for both tableC's id and tableB's id.
What did I do wrong?? :(
P.S. Maybe is this with something from documentation?? (http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html)
However, in the referenced table, there must be an index where the referenced columns are listed as the first columns in the same order.