MySQL - Error 1822

 
Vista:

Error 1822

Publicado por Error 1822 (1 intervención) el 25/08/2022 05:28:50
AYUDA

primary key (id_venta,id_producto,id_detalle),
constraint detalle_venta foreign key (id_venta) references Venta (id_ven),
constraint detalle_prod foreign key (id_producto) references Producto(id_prod)
) Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'detalle_prod' in the referenced table 'producto' 0.000 sec

he creado la tabla producto primero y despues detalle, producto corre bien pero a la hora de correr detalle, dice que hay un fallo en la restriccion pero aunque cambie nombre sigue dando error.

agradeceria cualquier ayuda.


Create table Producto
(
id_categoria int,
nit_proveedor int,
id_prod int,
nombre varchar(30),
precio float,
stock int not null,

primary key (id_categoria,nit_proveedor,id_prod),
constraint producto_id_categoria foreign key(id_categoria) references Categoria(ID_cat),
constraint producto_nit_proveedor foreign key(nit_proveedor) references Proveedor(Nit)
);

Create table Detalle
(
id_venta int,
id_producto int not null,
id_detalle varchar(20),
cantidad int,


primary key (id_venta,id_producto,id_detalle),
constraint detalle_venta foreign key (id_venta) references Venta (id_ven),
constraint detalle_prod foreign key (id_producto) references Producto(id_prod)
);
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder