I want to insert in a table column T_tiphab
but I can not tell me:
ERROR 1452 (23000): Can not add or update a child row: a foreign key constraint fails (
reservas
.T_tiphab
, CONSTRAINTT_tiphab_ibfk_1
FOREIGN KEY (codHotel
) REFERENCEST_hotel
(codHotel
))
The T_tiphab
table set it up like this:
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| tipo | varchar(255) | NO | PRI | | |
| numMaxPersonas | int(11) | YES | | NULL | |
| disponibilidad | int(11) | YES | | NULL | |
| codHotel | varchar(255) | NO | PRI | | |
| precio | double | YES | | NULL | |
+----------------+--------------+------+-----+---------+-------+
And the T_hotel
table is set up like this:
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| codHotel | varchar(255) | NO | PRI | | |
| nombre | varchar(255) | YES | | NULL | |
| fechaMaxEntrada | date | YES | | NULL | |
| numMaxNoches | int(11) | YES | | NULL | |
+-----------------+--------------+------+-----+---------+-------+
And it has the following records:
+----------+-----------------+-----------------+--------------+
| codHotel | nombre | fechaMaxEntrada | numMaxNoches |
+----------+-----------------+-----------------+--------------+
| 1 | HollydayInn | NULL | NULL |
| 2 | Sheraton | NULL | NULL |
| 3 | CincoEstrellas | NULL | NULL |
| 4 | CuatroEstrellas | NULL | NULL |
| 5 | DosEstrellas | NULL | NULL |
+----------+-----------------+-----------------+--------------+
How can I insert the T_tiphab
into the table without having to fill in all the columns?