MySQL no puede crear una restricción de clave externa

Tengo algunos problemas para crear una clave externa para una tabla existente en una base de datos mysql.

Tengo la mesaexp:

+-------------+------------------+------+-----+---------+-------+
| Field       | Type             | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+-------+
| EID         | varchar(45)      | NO   | PRI | NULL    |       |
| Comment     | text             | YES  |     | NULL    |       |
| Initials    | varchar(255)     | NO   |     | NULL    |       |
| ExpDate     | date             | NO   |     | NULL    |       |
| InsertDate  | date             | NO   |     | NULL    |       |
| inserted_by | int(11) unsigned | YES  | MUL | NULL    |       |
+-------------+------------------+------+-----+---------+-------+

y no voy a crear una nueva tabla llamadasample_df Haciendo referencia a esto, usando lo siguiente:

CREATE TABLE sample_df (
df_id mediumint(5) unsigned AUTO_INCREMENT primary key,
sample_type mediumint(5) unsigned NOT NULL,
df_10 BOOLEAN NOT NULL,
df_100 BOOLEAN NOT NULL,
df_1000 BOOLEAN NOT NULL,
df_above_1000 BOOLEAN NOT NULL,
target INT(11) unsigned NOT NULL,
assay MEDIUMINT(5) unsigned zerofill NOT NULL,
insert_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
inserted_by INT(11) unsigned NOT NULL,
initials varchar(255),
experiment VARCHAR(45),
CONSTRAINT FOREIGN KEY (inserted_by) REFERENCES user (iduser),
CONSTRAINT FOREIGN KEY (target) REFERENCES protein (PID),
CONSTRAINT FOREIGN KEY (sample_type) REFERENCES sample_type (ID),
CONSTRAINT FOREIGN KEY (assay) REFERENCES assays (AID),
CONSTRAINT FOREIGN KEY (experiment) REFERENCES exp (EID)
);

Pero me sale el error:

ERROR 1215 (HY000): Cannot add foreign key constraint

Para obtener algo más de información que hice:

SHOW ENGINE INNODB STATUS\G

De la cual obtuve:

FOREIGN KEY (experiment) REFERENCES exp (EID)
):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.

Para mí, los tipos de columna parecen coincidir, ya que ambos son varchar (45). (También intenté configurar elexperiment columna a no nula, pero esto no lo solucionó) Así que supongo que el problema debe ser queCannot find an index in the referenced table where the referenced columns appear as the first columns. Pero no estoy muy seguro de lo que esto significa, o cómo verificarlo / arreglarlo. ¿Alguien tiene alguna sugerencia? Y que se entiende porfirst columns?

SOLUCIÓN:

Resolví mi problema. Tuve una clasificación diferente para la tabla exp (utf8_unicode_ci) y luego el valor predeterminado para la base de datos (utf8_general_ci). Así que añadiendo

CHARACTER SET utf8 COLLATE utf8_unicode_ci

Al final de la consulta de creación de tablas se solucionó mi problema.

Pero sigo sintiendo curiosidad por lo que significafirst columns. ¿Es algo que ver con los índices?

Respuestas a la pregunta(9)

Su respuesta a la pregunta