Bug #22342
closedUnable to delete the host from foreman
Description
Foreman Version: 1.9.3
When the host is built using foreman, entry is made in tokens table for the host. I found 4 entries for the same host in tokens table. This results in foreman host record deletion error.
mysql> select * from tokens where host_id=110827;-------------------------------------------+---------------------+---------+
| id | value | expires | host_id |-------------------------------------------+---------------------+---------+
| 10148 | d0a939ab-f318-4bf8-bf57-f2d4caf98687 | 2018-01-05 02:05:21 | 110827 |
| 10149 | 9e11c00c-28c5-4e64-8c25-b59f14c42a07 | 2018-01-05 02:05:28 | 110827 |
| 10150 | e57c8428-c8e6-4181-abdf-233bb0067333 | 2018-01-05 02:05:33 | 110827 |
| 10151 | 33659bbc-3e87-432b-be6b-a2e65d0239aa | 2018-01-05 02:05:33 | 110827 |-------------------------------------------+---------------------+---------+
ERROR in foreman UI:
Warning!
Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails (`foreman`.`tokens`, CONSTRAINT `tokens_host_id_fk` FOREIGN KEY (`host_id`) REFERENCES `hosts` (`id`)): DELETE FROM `hosts` WHERE `hosts`.`type` IN ('Host::Managed') AND `hosts`.`id` = 110827
Let me know if you need additional information.