Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/01/2013, 10:37
vmelero
 
Fecha de Ingreso: octubre-2010
Mensajes: 88
Antigüedad: 13 años, 7 meses
Puntos: 1
Problemas con foreign key

Hola a todos,tengo problemas con una tabla de las que estoy intentando crear y buscando por internet parece ser que tengo un problema con la foreign que intento crear en dicha tabla.

La primera tabla es codigopostal que defino de la siguiente manera y se crea bien:
Código MySQL:
Ver original
  1. create table codigopostal(idCodPostal tinyint(5) NOT NULL auto_increment,
  2. CodPos varchar(5) NOT NULL DEFAULT '' ,
  3. Localidad varchar(50) NOT NULL DEFAULT '' ,
  4. Provincia varchar(50) NOT NULL DEFAULT '' ,
  5. PRIMARY KEY (idCodPostal),
  6. KEY (CodPos),
  7. UNIQUE (idCodPostal)
La segunda es clientes que tiene una foreign key a codigo postal y también se crea bien
Código MySQL:
Ver original
  1. nombre varchar(50) NOT NULL DEFAULT '' ,
  2. apellido1 varchar(50) NOT NULL DEFAULT '' ,
  3. apellido2 varchar(50),
  4. todocliente varchar(250)NOT NULL DEFAULT '' ,
  5. Identificacion varchar(10) NOT NULL DEFAULT '' ,
  6. email varchar(50),
  7. tel varchar(9),
  8. tienecontratos  TINYINT(1),
  9. fk_CodPostal tinyint(5),
  10. PRIMARY KEY(idCliente),
  11. KEY(Identificacion),
  12. UNIQUE (idCliente),
  13. FOREIGN KEY(fk_CodPostal) REFERENCES codigopostal(idCodPostal))
Y por ultimo la tabla contratos que es donde tengo el problema. Estoy intentando crearle una foreign a clientes pero me aparece el error 150
Código MySQL:
Ver original
  1. create table contratos (id_Contrato tinyint(5) unsigned NOT NULL auto_increment,
  2. FechaCon date NOT NULL default '0000-00-00',
  3. Descripcion varchar(255) NOT NULL DEFAULT '' ,
  4. BaseImp double NOT NULL DEFAULT '0' ,
  5. ImporTot double NOT NULL DEFAULT '0' ,
  6. Pagado tinyint(1) NOT NULL DEFAULT '0',
  7. fk_cliente tinyint(5),
  8. PRIMARY KEY(id_Contrato),
  9. FOREIGN KEY(fk_cliente) REFERENCES clientes(idCliente))
A ver si me podeis decir donde está el error, porque soy novata en mysql y no me entero todavía muy bien.

Gracias

Última edición por gnzsoloyo; 19/01/2013 a las 10:53 Razón: Etiquetas de código incorrectas. Usar Highlight "MySQL" o "SQL"