Bases de Datos > MySQL
Problema creando llave foranea mysql innodb err 150
(1/1)
acek:
Buenos Dias Compañeros de solo codigo,
Me encuentro en mo proyecto de tesis haciendo un sistema de informacion para un colegio, pero tengo un leve problema creando mi base de datos, yo soy nuevo en mysql y pues use el mysql workbench para crear el modelo de la base de datos y exportarlo como script de mysql pero me esta generando un inconveniente en la creacion de la tabla principal de mi sistema, no se si uds me puedan colaborar para detectar mi error , ya me parti el craneo :hitcomp: revisando y no doy con el error,
le paso los scripts con los que creo las 3 tablas que quiero relacionar.
--- Código: SQL ----- ------------------------------------------------------- Table colegio.TiposDocmnts-- -----------------------------------------------------CREATE TABLE IF NOT EXISTS colegio.TiposDocmnts ( Tipo_Docmnt CHAR(3) NOT NULL , Descripcion_Docmnt VARCHAR(30) NOT NULL , PRIMARY KEY (Tipo_Docmnt) INDEX Index_TipDocs (Tipo_Docmnt ASC) , )ENGINE = InnoDBDEFAULT CHARACTER SET = latin1COLLATE = latin1_general_ci;
--- Código: SQL ----- ------------------------------------------------------- Table colegio.Ciudades-- -----------------------------------------------------CREATE TABLE IF NOT EXISTS colegio.Ciudades ( Cod_Dane_Ciudad CHAR(5) NOT NULL , Nombre_Ciudd VARCHAR(20) NOT NULL , Ind_Capital DECIMAL(1) NULL , PRIMARY KEY (Cod_Dane_Ciudad) , INDEX Index_Ciudades (Cod_Dane_Ciudad ASC, Nombre_Ciudd ASC) )ENGINE = InnoDB;
--- Código: SQL ----- ------------------------------------------------------- Table colegio.Personas-- -----------------------------------------------------CREATE TABLE IF NOT EXISTS colegio.Personas ( Numero_Docmnt DECIMAL(12) NOT NULL , TiposDocmnts_Tipo_Docmnt CHAR(3) NOT NULL , Codigo_Persona DECIMAL(7) NOT NULL , Fecha_Expdcn_Docmnt DATE NOT NULL , Rh CHAR(3) NULL , Primer_Nombr VARCHAR(20) NOT NULL , Segundo_Nombr VARCHAR(20) NOT NULL , Primer_Apelld VARCHAR(20) NOT NULL , Segundo_Apelld VARCHAR(20) NOT NULL , Sexo CHAR(1) NOT NULL , fecha_alta DATE NOT NULL , Fecha_Ultm_Modfccn TIMESTAMP NOT NULL , Fecha_Nacmnt DATE NOT NULL , Foto BIT NULL , Direccion VARCHAR(60) NOT NULL , Telefono DECIMAL(10) NOT NULL , Barrio VARCHAR(20) NOT NULL , EMail VARCHAR(30) NOT NULL , Telefono2 DECIMAL(10) NULL , Movil DECIMAL(10) NULL , Tipo_De_Alt VARCHAR(2) NULL , Ciudd_Expedcn_Docmnt CHAR(5) NOT NULL , Ciudad_Nacimiento CHAR(5) NULL , PRIMARY KEY (Codigo_Persona, Numero_Docmnt, TiposDocmnts_Tipo_Docmnt) , INDEX fk_Personas_Ciudades (Ciudd_Expedcn_Docmnt ASC) , INDEX fk_Personas_Ciudades1 (Ciudad_Nacimiento ASC) , INDEX fk_Personas_TiposDocmnts (TiposDocmnts_Tipo_Docmnt ASC) , CONSTRAINT fk_Personas_Ciudades FOREIGN KEY (Ciudd_Expedcn_Docmnt ) REFERENCES colegio.Ciudades (Cod_Dane_Ciudad ) ON DELETE RESTRICT ON UPDATE NO ACTION, CONSTRAINT fk_Personas_Ciudades1 FOREIGN KEY (Ciudad_Nacimiento ) REFERENCES colegio.Ciudades (Cod_Dane_Ciudad ) ON DELETE RESTRICT ON UPDATE NO ACTION, CONSTRAINT fk_Personas_TiposDocmnts FOREIGN KEY (TiposDocmnts_Tipo_Docmnt ) REFERENCES colegio.TiposDocmnts (Tipo_Docmnt ) ON DELETE RESTRICT ON UPDATE NO ACTION)ENGINE = InnoDBPACK_KEYS = DEFAULT;
el error que me retorna mysql por linea de comandos es :
--- Código: Text ---------------------------LATEST FOREIGN KEY ERROR------------------------090404 11:04:38 Error in foreign key constraint of table colegio/personas: FOREIGN KEY (TiposDocmnts_Tipo_Docmnt ) REFERENCES colegio.TiposDocmnts (Tipo_Docmnt ) ON DELETE RESTRICT ON UPDATE NO ACTION)ENGINE = InnoDBPACK_KEYS = DEFAULT:Cannot find an index in the referenced table where thereferenced columns appear as the first columns, or column typesin the table and the referenced table do not match for constraint.Note that the internal storage type of ENUM and SET changed intables created with >= InnoDB-4.1.12, and such columns in old tablescannot be referenced by such columns in new tables.See http://dev.mysql.com/doc/refman/5.1/en/ ... aints.htmlfor correct foreign key definition. se que tengo un problema en la creacion de la tabla tipo_documentos o en la asignacion de la llave foranea :wacko:
:good: le agradesco a quien me pueda colaborar mil gracias :D
Navegación
Ir a la versión completa