If you encounter the error 1005 you probably have someting wrong in your tables.
You should check some things:
* Table Engine value must be the same for both tables, for example InnoDB
* Columns type must be the same for the referenced column, for example INT(11) UNSIGNED
* Both column must be indexed, for example PRIMARY KEY, INDEX, UNIQUE