22

I wanted to edit the actions in a table. However I get the error message "Please specify covering index name." when I try to edit the FK. How do I fix this?

The table consists of only two columns:

picture of database table

The foreign keys:

foreign keys

category FK:

category FK

NullOrNotNull
  • 365
  • 1
  • 4
  • 11
  • 1
    I think that that error is coming from pgAdmin itself, not from PostgreSQL. What edit are you trying to make? Is the image shown the pre-edit state, or the post-edit state which you are not allowed to save? – jjanes Apr 26 '20 at 13:29
  • And what version of both PostgreSQL and pgAdmin4 are you using? – jjanes Apr 26 '20 at 13:30
  • The pictures are pre-edit. I want to change the "on delete" action from no action to cascade. – NullOrNotNull Apr 26 '20 at 13:37
  • The pgadmin is on 4.20, the install psql version is 11.7 (Raspbian 11.7-0+deb10u1) – NullOrNotNull Apr 26 '20 at 13:37
  • Yea I suppose you're right about this being a PG Admin problem .. I deleted the foreign keys, added them, added the actions and saved. Their FK actions are now on cascade. Now, when I try to change the FK properties again I got the same problem again - but it's still set to on cascade. – NullOrNotNull Apr 26 '20 at 14:08
  • Same problem here: I cannot delete/modify foreign key using PgAdmin interface, but I can do the same using sql queries with ALTER TABLE. – Giorgio R Jun 29 '20 at 07:53

12 Answers12

36

Temporary workaround: Using pgAdmin

If you have a single foreign key:

Click on edit to expand, and click on it again to collapse, save button should be re-enable again.

If you have multiple foreign keys:

Repeat on every foreign key entry, click edit and "un-edit" for every foreign key, the Save button should be re-enable after every one of it is clicked.

Usually, whenever the error pop up when I want to add anything to the constraint, I will just expand and collapse every foreign key, save button should be working again.

For action,

If you want to add an action, eg: On update/On delete

The error message will pop up again. Don't forget to click on the '+' button to add the column, then repeat above steps(expand, collapse) to clear the error message, then you can save the foreign key. Yeah~ I know it is ugly...

For updating action for existing foreign key

Currently, I don't know any workaround, but the ugly way...

Delete the fkey -> recreate the foreign-key -> update the action -> clear the error message with above steps -> save.

cYee
  • 1,915
  • 1
  • 16
  • 24
  • 1
    This worked for me to clear the error message "please specify covering index name” but not to enable editing of the FK action. As mentioned by @jjanes, I think that action is not possible. – Mark Hansen Jul 13 '20 at 12:40
  • 1
    @MarkHansen Did you press the '+' icon to add the column? then add action. I tried, it works for me. For editing, yeah, it is greyed out, I have to delete the key and then create a new key to update the action. – cYee Jul 13 '20 at 14:18
  • I am glad, it helped you. – cYee Sep 07 '20 at 01:04
  • 1
    This should be marked as the correct answer – Vijay B Dec 21 '20 at 03:32
  • 1
    It's a glitch in the INTERFACE. – Vectoria Feb 03 '21 at 11:39
11

in our case this helped: before saving "new FK", firstly open "edit options" of "previously created FK", and DO NOT CHANGE anything then return to "newly created FK" edit options, save button magically activated

Asad
  • 326
  • 2
  • 7
6

I can't reproduce your problem, as pgAdmin4 won't let me change anything about a constraint (other than its name) in the first place, so I can't get to the point where it would throw me an error like that. All the affordances to make changes are there, but they are all greyed out.

Also, PostgreSQL itself won't let you change an action on a FK constraint (there is simply no variant of "ALTER TABLE" which implements it), so you have to drop and recreate. So it is not surprising pgAdmin4 wont let me model such an action when it can't be done.

I don't know how you are getting it to produce this error, but it is probably a presentation bug in pgAdmin4, it is reporting an error condition as an error, but with a unhelpful message.

jjanes
  • 37,812
  • 5
  • 27
  • 34
2

I had the same problem. It's really hard to reproduce it.

I needed to add several foreign keys. So I started to add new columns and new foreign keys. At some point, there was this error "Please specify covering index name." after every action in pgAdmin. Maybe I used an incorrect name for a column because I copypasted the names and there may be incorrect symbols, I don't know.

So to fix it I reverted all my updates: deleted all new foreign keys and new columns. And then this error disappeared.

As another solution I thought it is better to just write SQL queries to add some foreign keys.

SashkaCosmonaut
  • 413
  • 8
  • 18
  • i guess that @jjanes is simply correct. you cannot edit FKs afterwards - not in PG Admin nor PostgreSQL. Changing it means that you have to delete and recreate it. At least thats what I can confirm from my experience now – NullOrNotNull May 16 '20 at 19:28
1

What worked in my case - if you manually turn on "Validated?" option on the newly created foreign key and open "edit" on the previously created foreign key, then the message disappears and you can save the constraint. Seems like some kind of bug.

gharik_cz
  • 11
  • 2
1

Here is my solution:

  1. Table -> Property -> Constraints -> Foreign Key -> click delete icon for all foreign key.

  2. Table -> Property -> Constraints -> Foreign Key -> Add again foreign key.

I guess you alter current FK or add new FK that causing this issue.

Hoang Subin
  • 6,610
  • 6
  • 37
  • 56
0

I had the same error. The problem was that a I had another foreign key with the same name in other table. I think postgres tracks the covering index and the name of the foreign key and don't allow the same name. So you have to use another name.

Joel
  • 315
  • 1
  • 10
0

I just solved this, according to https://www.pgadmin.org/docs/pgadmin4/4.19/foreign_key_dialog.html the covering index warning is activated when the "Auto FK Index" is selected when creating the foreign key. This is enabled by default. I went through and unchecked it on each of the indexes on the table that was giving me the issue and the message went away.

0

The problem happened randomly for me. I just found that If I go to constraints -> primary key tab and click the trash icon and then when confirming delete dialog comes I cancel it and boom, the error disappears and the save button is enabled!

Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93
0

just type the foreign key index name ... few letters fki_index_name (if you want an index generated "auto FK index" or turn it off!

And yes it looks like a bug in pgadmin not postgresql

Smart.Man
  • 41
  • 5
0

PgAdmin has a browser at left side, select table and then go to Constraints, do a right click on the foreign key that you want to change, after that in properties you will be able to change it.

Duarte
  • 1
  • 1
0

Try adding column using query tool:

ALTER TABLE x ADD COLUMN c INT NOT NULL
CONSTRAINT xy_fk_c REFERENCES y (a)

Where: x will be current table name, c will be column that you want to be created, xy_fk_c will be foreign key name, y will be the reference of your foreign table and a will be the referencing column.

Mayur Saner
  • 444
  • 5
  • 10