How to insert data in a single column?

0

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 , CONSTRAINT T_tiphab_ibfk_1 FOREIGN KEY ( codHotel ) REFERENCES T_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?

    
asked by TOMAS 05.01.2018 в 01:34
source

1 answer

1

The error you have is due to the foreign key you have in t_tiphab to the T_hotel table, the data you are entering in the codHotel does not exist in that table. To fix this make sure you have the registration in T_hotel or otherwise enter it. Greetings.

    
answered by 05.01.2018 в 02:24