Bug #3194

Ugly errors when destroy actions are stopped by FKs

Added by Dominic Cleal about 4 years ago. Updated over 3 years ago.

Status:Duplicate
Priority:Normal
Assigned To:-
Category:Database
Target version:-
Difficulty: Bugzilla link:
Found in release: Pull request:
Story points-
Velocity based estimate-

Description

Server errors aren't very helpful when an FK prevents a destroy:

PG::ForeignKeyViolation: ERROR:  update or delete on table "smart_proxies" violates foreign key constraint "subnets_dhcp_id_fk" on table "subnets" 
DETAIL:  Key (id)=(1) is still referenced from table "subnets".
: DELETE FROM "smart_proxies" WHERE "smart_proxies"."id" = $1
   (145.2ms)  ROLLBACK
Completed 500 Internal Server Error in 3385ms

Related issues

Related to Foreman - Feature #2400: Add foreign keys on database level Closed 04/15/2013
Related to Hammer CLI - Bug #4033: Need a clearer / user friendly message when deletion of s... Duplicate 01/16/2014
Related to Foreman - Bug #4415: FK error when deleting a smart proxy Duplicate 02/23/2014
Duplicates Foreman - Bug #5788: before_destroy missing from EnsureNotUsedBy.new in SmartP... Closed 05/19/2014

History

#1 Updated by Dominic Cleal about 4 years ago

  • Related to Feature #2400: Add foreign keys on database level added

#2 Updated by Dominic Cleal about 4 years ago

And equally ugly in MySQL..

Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails (`puppet`.`hostgroups`, CONSTRAINT `hostgroups_puppet_ca_proxy_id_fk` FOREIGN KEY (`puppet_ca_proxy_id`) REFERENCES `smart_proxies` (`id`)): DELETE FROM `smart_proxies` WHERE `smart_proxies`.`id` = 4

#3 Updated by Dominic Cleal almost 4 years ago

  • Related to Bug #4033: Need a clearer / user friendly message when deletion of smart proxy fails added

#4 Updated by Dominic Cleal almost 4 years ago

  • Related to Bug #4415: FK error when deleting a smart proxy added

#5 Updated by Dominic Cleal over 3 years ago

  • Duplicates Bug #5788: before_destroy missing from EnsureNotUsedBy.new in SmartProxy model added

#6 Updated by Dominic Cleal over 3 years ago

  • Status changed from New to Duplicate

We had a helper whose job it was to provide friendly messages, but it wasn't invoked correctly. #5788 has fixed this.

#7 Updated by Dominic Cleal over 3 years ago

  • Bugzilla link set to https://bugzilla.redhat.com/show_bug.cgi?id=1109315

#8 Updated by Dominic Cleal over 3 years ago

  • Bugzilla link deleted (https://bugzilla.redhat.com/show_bug.cgi?id=1109315)

Also available in: Atom PDF