MySQL Forums
Forum List  »  Spanish

Re: problema en claves foraneas
Posted by: William Chiquito
Date: October 14, 2006 10:31AM

Diego,

El problema que tienes es que los tipos de datos de la tabla vista para las columnas FKconsorcioidConsorcio y FKproveedorcuil no son del mismo tipo de datos que lo definidos en las tablas consorcio y proveedor. Es por ello que al tratar de crear las claves foráneas falla.

Aquí te dejo un script que te puede ser útil.

SET NAMES utf8;

SET SQL_MODE='';

create database if not exists `consorcios`;

USE `consorcios`;

SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';

DROP TABLE IF EXISTS `consorcio`;

CREATE TABLE `consorcio` (
`idConsorcio` int(10) unsigned NOT NULL auto_increment,
`direccion` varchar(45) NOT NULL,
`m2Totales` float NOT NULL default '0',
PRIMARY KEY (`idConsorcio`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `proveedor`;

CREATE TABLE `proveedor` (
`cuil` int(10) unsigned NOT NULL,
`tipo` varchar(45) NOT NULL,
`razonSocial` varchar(45) NOT NULL,
PRIMARY KEY (`cuil`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `visita`;

CREATE TABLE `visita` (
`FKconsorcioidConsorcio` int(10) unsigned NOT NULL,
`FKproveedorcuil` int(10) unsigned NOT NULL,
`fecha` date NOT NULL,
`hora` time NOT NULL,
`motivo` varchar(250) NOT NULL,
PRIMARY KEY (`FKconsorcioidConsorcio`,`FKproveedorcuil`),
KEY `FK_visita` (`FKproveedorcuil`),
CONSTRAINT `visita_ibfk_1` FOREIGN KEY (`FKconsorcioidConsorcio`) REFERENCES `consorcio` (`idConsorcio`),
CONSTRAINT `visita_ibfk_2` FOREIGN KEY (`FKproveedorcuil`) REFERENCES `proveedor` (`cuil`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

Options: ReplyQuote


Subject
Views
Written By
Posted
3413
October 14, 2006 09:24AM
Re: problema en claves foraneas
4091
October 14, 2006 10:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.