Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreign key reference tables are blank #786

Closed
MarcelloTheArcane opened this issue Oct 31, 2019 · 12 comments
Closed

Foreign key reference tables are blank #786

MarcelloTheArcane opened this issue Oct 31, 2019 · 12 comments

Comments

@MarcelloTheArcane
Copy link

Steps to reproduce this issue

  1. Step 1; Go to a table and select Foreign keys
  2. Step 2; Add a key name and select a column
  3. Step 3; Click the reference table dropdown
  4. Then I get... nothing!

Current behavior

No tables show in the dropdown:

image

Expected behavior

All the tables should be listed in the Reference table box for me to select.

Environment

  • HeidiSQL version: 10.2.0.5599
  • Database system and version: PostgreSQL 10.5
  • Operating system: Windows 10
@ansgarbecker
Copy link
Collaborator

I suppose you are the first one reorting that issue for PostgreSQL. And I think the feature was not well tested by myself on PostgreSQL. So let's get foreign keys to work on PostgreSQL.

@MarcelloTheArcane
Copy link
Author

Yep, that was me.

@rwilliams
Copy link

Also already created foreign keys do not show up on postgres. Using postgres 11.5.3

@halmai
Copy link

halmai commented Jan 25, 2020

The bug is still present with

Version 10.3.0.5837 (64 Bit)
Compiled on: 2020-01-19 19:55:50

@ansgarbecker
Copy link
Collaborator

Could you please check with the latest build (5848 currently)

@rwilliams
Copy link

Reference table does not populate and created foreign keys do not show. Build 5849. psql (PostgreSQL) 12.1 (Debian 12.1-1.pgdg100+1)

@ansgarbecker ansgarbecker pinned this issue Jan 26, 2020
@ansgarbecker
Copy link
Collaborator

What would be a good SQL approach to retrieve foreign keys of one table? I know I can join pg_index with pg_class to get many index details, but for HeidiSQL that query should deliver also the reference table and columns from source and reference table:

SELECT * FROM pg_index i, pg_class c
WHERE
    i.indexrelid=c.oid

@rwilliams
Copy link

rwilliams commented Jan 26, 2020

I found this on Stack overflow

SELECT
    tc.table_schema, 
    tc.constraint_name, 
    tc.table_name, 
    kcu.column_name, 
    ccu.table_schema AS foreign_table_schema,
    ccu.table_name AS foreign_table_name,
    ccu.column_name AS foreign_column_name 
FROM 
    information_schema.table_constraints AS tc 
    JOIN information_schema.key_column_usage AS kcu
      ON tc.constraint_name = kcu.constraint_name
      AND tc.table_schema = kcu.table_schema
    JOIN information_schema.constraint_column_usage AS ccu
      ON ccu.constraint_name = tc.constraint_name
      AND ccu.table_schema = tc.table_schema
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='truck_setups_workers';
"table_schema"	"constraint_name"	"table_name"	"column_name"	"foreign_table_schema"	"foreign_table_name"	"foreign_column_name"
"public"	"fk_rails_d00006069d"	"truck_setups_workers"	"truck_setup_id"	"public"	"truck_setups"	"id"
"public"	"fk_rails_a1cce43842"	"truck_setups_workers"	"employee_id"	"public"	"employees"	"id"

@rwilliams
Copy link

In 5850 it looks like the reference tables are now populating.

@ansgarbecker
Copy link
Collaborator

In 5850 it looks like the reference tables are now populating.

Really, in PostgreSQL? Or on MySQL or MS SQL?

@rwilliams
Copy link

rwilliams commented Jan 28, 2020

PostgreSQL

image

Just tested 5771 and it definitely doesn't populate there.

@ansgarbecker
Copy link
Collaborator

Oh yes, I was mixing this issue with #158 , which complains about non working detection of foreign keys. This one is just for the reference tables, which I fixed in conjunction with 7ab47a3 for #150 .
Thanks for your feedback!

@ansgarbecker ansgarbecker unpinned this issue Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants