Reputation: 3
When connecting the flight table books table and company I get the error 1215. I have no problems connecting the other tables. Can anyone tell me what is wrong?
create database aviacion;
use aviacion;
create Table Compañia(
Codigo char(8) NOT NULL,
Nombre varchar(15),
Volumen_venta decimal(10,0)
);
create Table Pais(
Codigo char(8) NOT NULL,
Nombre varchar(10),
Idioma varchar(10),
Moneda varchar(10)
);
create Table Avion(
Nombre varchar(10) NOT NULL,
Consumo_gas int(8),
Cantidad_asientos int(25)
);
create Table Viaje(
Codigo char(8) NOT NULL,
Lugar varchar(10),
Destino varchar(10),
Cantidad_km int(8)
);
create Table Vuelo(
Precio decimal(10,0) NOT NULL,
Tiempo_duracion datetime NOT NULL
);
Alter Table Compañia Add Primary Key (Codigo);
Alter Table Pais Add Primary Key (Codigo);
Alter Table Avion Add Primary Key (Nombre);
Alter Table Viaje Add Primary Key (Codigo);
Alter Table Vuelo Add Primary Key (Precio);
Alter Table Pais Add Foreign Key (Codigo) References Compañia(Codigo);
Alter Table Avion Add Foreign Key (Nombre) References Pais(Codigo);
Alter Table Viaje Add Foreign Key (Codigo) References Avion(Nombre);
Alter Table Vuelo Add Foreign Key (Precio) References Viaje(Codigo);
Alter Table Vuelo Add Foreign Key (Precio) References Compañia(Codigo);
Upvotes: 0
Views: 75
Reputation: 191
First try create database without the foreign keys and check if it works.
When you try to add the foreign key to this part
ALTER TABLE Vuelo ADD FOREIGN KEY (Precio) REFERENCES Compañia(Codigo);
You're using a different Datatype.
Precio
is a Decimal Datatype, Compañia(Codigo)
is a char, but Foreign Keys must have to have the same Datatype.
Upvotes: 2