Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL - Foreign Key referencing multiple tables

I've got this problem at a postgres database. I have four tables of location data (hospitals, schools, markets and police precints), slightly different between themselves, and a event report table that has a location column, referencing a location.

How can I make this reference, to a id that can be in any of the location tables? I've tried to reference a parent table of them all, but inserts return an error of "key not present at table"

Thanks

like image 449
ebarbara Avatar asked Feb 05 '26 00:02

ebarbara


1 Answers

Per Kouber Saparev's suggestion, I've removed the inheritance and used foreign keys to reference the parent from the children. It's working perfectly now.

like image 149
ebarbara Avatar answered Feb 06 '26 12:02

ebarbara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!