title: MySQL ERROR 1215 (HY000): Cannot add foreign key constraint
body: <p>I have looked everywhere about this error and seen plenty of examples and still i cant figure out whats wrong with my script. Im sorry if this is a common issue but searching about it hasnt helped me so far. Here goes the script:</p>
  
  <pre><code>CREATE DATABASE IF NOT EXISTS ventas;
  USE ventas
  
  CREATE TABLE TIENDAS (
  nif varchar(10) not null,
  nombre varchar(20),
  direccion varchar(20),
  poblacion varchar(20),
  provincia varchar(20) check (provincia = upper(provincia)),
  codpostal int(5),
  PRIMARY KEY (nif)
  ) ENGINE=INNODB;
  
  CREATE TABLE FABRICANTES (
  cod_fabricante int(3) not null,
  nombre varchar(15) check (nombre = upper(nombre)),
  pais varchar(15) check (pais = upper(pais)),
  PRIMARY KEY (cod_fabricante)
  ) ENGINE=INNODB;
  
  CREATE TABLE ARTICULOS (
  articulo varchar(20) not null,
  cod_fabricante int(3) not null,
  peso int(3) unsigned not null CHECK (peso &gt; 0),
  categoria varchar(10) not null,
  precio_venta int(4) unsigned CHECK (precio_venta &gt; 0),
  precio_costo int(4) unsigned CHECK (precio_costo &gt; 0),
  existencias int(5),
  PRIMARY KEY (articulo,cod_fabricante,peso,categoria),
  FOREIGN KEY (cod_fabricante) references FABRICANTES (cod_fabricante)
  ) ENGINE=INNODB;
  
  CREATE TABLE PEDIDOS (
  nif varchar(10) not null,
  articulo varchar(20) not null,
  cod_fabricante int(3) not null,
  peso int(3) unsigned not null CHECK (peso &gt; 0),
  categoria varchar(10) not null,
  fecha_pedido date not null,
  unidades_pedidas int(4),
  PRIMARY KEY (nif,articulo,cod_fabricante,peso,categoria,fecha_pedido),
  FOREIGN KEY (cod_fabricante) references FABRICANTES (cod_fabricante),
  FOREIGN KEY (articulo) references ARTICULOS (articulo) ON DELETE CASCADE,
  FOREIGN KEY (cod_fabricante) references ARTICULOS (cod_fabricante) ON DELETE CASCADE,
  FOREIGN KEY (peso) references ARTICULOS (peso) ON DELETE CASCADE,
  FOREIGN KEY (categoria) references ARTICULOS (categoria) ON DELETE CASCADE,
  FOREIGN KEY (nif) references TIENDAS (nif)
  ) ENGINE=INNODB;
  </code></pre>
  
  <p>Thanks a lot for your help.</p>