• Domingo 28 de Abril de 2024, 22:52

Autor Tema:  Problema creando llave foranea mysql innodb err 150  (Leído 2068 veces)

acek

  • Miembro activo
  • **
  • Mensajes: 58
  • Nacionalidad: co
    • Ver Perfil
Problema creando llave foranea mysql innodb err 150
« en: Sábado 4 de Abril de 2009, 18:12 »
0
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
  1. -- -----------------------------------------------------
  2. -- Table colegio.TiposDocmnts
  3. -- -----------------------------------------------------
  4. CREATE  TABLE IF NOT EXISTS colegio.TiposDocmnts (
  5.   Tipo_Docmnt CHAR(3) NOT NULL ,
  6.   Descripcion_Docmnt VARCHAR(30) NOT NULL ,
  7.   PRIMARY KEY (Tipo_Docmnt)
  8.   INDEX Index_TipDocs (Tipo_Docmnt ASC) ,
  9.  )
  10. ENGINE = InnoDB
  11. DEFAULT CHARACTER SET = latin1
  12. COLLATE = latin1_general_ci;
  13.  
Código: SQL
  1. -- -----------------------------------------------------
  2. -- Table colegio.Ciudades
  3. -- -----------------------------------------------------
  4. CREATE  TABLE IF NOT EXISTS colegio.Ciudades (
  5.   Cod_Dane_Ciudad CHAR(5) NOT NULL ,
  6.   Nombre_Ciudd VARCHAR(20) NOT NULL ,
  7.   Ind_Capital DECIMAL(1) NULL ,
  8.   PRIMARY KEY (Cod_Dane_Ciudad) ,
  9.   INDEX Index_Ciudades (Cod_Dane_Ciudad ASC, Nombre_Ciudd ASC) )
  10. ENGINE = InnoDB;
  11.  
Código: SQL
  1. -- -----------------------------------------------------
  2. -- Table colegio.Personas
  3. -- -----------------------------------------------------
  4. CREATE  TABLE IF NOT EXISTS colegio.Personas (
  5.   Numero_Docmnt DECIMAL(12) NOT NULL ,
  6.   TiposDocmnts_Tipo_Docmnt CHAR(3) NOT NULL ,
  7.   Codigo_Persona DECIMAL(7) NOT NULL ,
  8.   Fecha_Expdcn_Docmnt DATE NOT NULL ,
  9.   Rh CHAR(3) NULL ,
  10.   Primer_Nombr VARCHAR(20) NOT NULL ,
  11.   Segundo_Nombr VARCHAR(20) NOT NULL ,
  12.   Primer_Apelld VARCHAR(20) NOT NULL ,
  13.   Segundo_Apelld VARCHAR(20) NOT NULL ,
  14.   Sexo CHAR(1) NOT NULL ,
  15.   fecha_alta DATE NOT NULL ,
  16.   Fecha_Ultm_Modfccn TIMESTAMP NOT NULL ,
  17.   Fecha_Nacmnt DATE NOT NULL ,
  18.   Foto BIT NULL ,
  19.   Direccion VARCHAR(60) NOT NULL ,
  20.   Telefono DECIMAL(10) NOT NULL ,
  21.   Barrio VARCHAR(20) NOT NULL ,
  22.   EMail VARCHAR(30) NOT NULL ,
  23.   Telefono2 DECIMAL(10) NULL ,
  24.   Movil DECIMAL(10) NULL ,
  25.   Tipo_De_Alt VARCHAR(2) NULL ,
  26.   Ciudd_Expedcn_Docmnt CHAR(5) NOT NULL ,
  27.   Ciudad_Nacimiento CHAR(5) NULL ,
  28.   PRIMARY KEY (Codigo_Persona, Numero_Docmnt, TiposDocmnts_Tipo_Docmnt) ,
  29.   INDEX fk_Personas_Ciudades (Ciudd_Expedcn_Docmnt ASC) ,
  30.   INDEX fk_Personas_Ciudades1 (Ciudad_Nacimiento ASC) ,
  31.   INDEX fk_Personas_TiposDocmnts (TiposDocmnts_Tipo_Docmnt ASC) ,
  32.   CONSTRAINT fk_Personas_Ciudades
  33.     FOREIGN KEY (Ciudd_Expedcn_Docmnt )
  34.     REFERENCES colegio.Ciudades (Cod_Dane_Ciudad )
  35.     ON DELETE RESTRICT
  36.     ON UPDATE NO ACTION,
  37.   CONSTRAINT fk_Personas_Ciudades1
  38.     FOREIGN KEY (Ciudad_Nacimiento )
  39.     REFERENCES colegio.Ciudades (Cod_Dane_Ciudad )
  40.     ON DELETE RESTRICT
  41.     ON UPDATE NO ACTION,
  42.   CONSTRAINT fk_Personas_TiposDocmnts
  43.     FOREIGN KEY (TiposDocmnts_Tipo_Docmnt )
  44.     REFERENCES colegio.TiposDocmnts (Tipo_Docmnt )
  45.     ON DELETE RESTRICT
  46.     ON UPDATE NO ACTION)
  47. ENGINE = InnoDB
  48. PACK_KEYS = DEFAULT;
  49.  

el error que me retorna mysql por linea de comandos es :

Código: Text
  1. ------------------------
  2. LATEST FOREIGN KEY ERROR
  3. ------------------------
  4. 090404 11:04:38 Error in foreign key constraint of table colegio/personas:
  5.  
  6.     FOREIGN KEY (TiposDocmnts_Tipo_Docmnt )
  7.     REFERENCES colegio.TiposDocmnts (Tipo_Docmnt )
  8.     ON DELETE RESTRICT
  9.     ON UPDATE NO ACTION)
  10. ENGINE = InnoDB
  11. PACK_KEYS = DEFAULT:
  12. Cannot find an index in the referenced table where the
  13. referenced columns appear as the first columns, or column types
  14. in the table and the referenced table do not match for constraint.
  15. Note that the internal storage type of ENUM and SET changed in
  16. tables created with >= InnoDB-4.1.12, and such columns in old tables
  17. cannot be referenced by such columns in new tables.
  18. See http://dev.mysql.com/doc/refman/5.1/en/ ... aints.html
  19. for correct foreign key definition.
  20.  
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
http://twitter.com/aceherdz http://xavijava.blogspot.com/
Si Lo que crei que era mi realidad es una mentira;
 y las mentiras Son Mi Realidad . a Que Put@s Juego?
>>>>AceK<<<<
JAVA!!!!!!
COBOL
 PHP!!!!!!!!
http://www.tupokemon.com/adopcion/index.php?sumarExperiencia=164964