Re: Foreign key UI bug

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Aren Cambre <aren(at)arencambre(dot)com>
Cc: pgadmin-support(at)postgresql(dot)org
Subject: Re: Foreign key UI bug
Date: 2010-11-20 11:24:24
Message-ID: 4CE7AFE8.1020108@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

Le 20/11/2010 04:50, Aren Cambre a écrit :
> I found a UI bug when creating a foreign key.
>
> When creating a primary key, all you have to do is select the column in the
> *Columns* tab of the dialog. You don't have to fill out any other fields;
> pgadmin appears to take care of this for you.
>
> It seems then that with a foreign key, all you should have to fill out is
> fill out the *References* field in the *Properties *tab, then in the *
> Columns* tab just select the relevant columns. If I do this and press OK, I
> get this error:
>
> *An error has occurred:*
> *ERROR: relation "fki_" already exists.*
>
> *
> *
> If I go back to the *Properties* tab and enter something into the *Name* field,
> then press *OK*, it works.
>
> The problem: I don't need to enter anything in the *Name* field of primary
> key dialogs, but I do with foreign key dialogs. Can it be consistent where I
> don't need to enter a *Name* field of the foreign key, either.
>

The issue is not really with the creation of the foreign key, but more
with the automatically created index. If you don't put a name to the
foreign key, pgAdmin has no idea on the name of index.

The code says the index name would be "fki_" followed by the name of the
foreign key. But, when pgadmin fires the SQL, it has no idea what the
foreign key name will look like if you didn't specify it. So if you
tries to create more than one foreign key, they end ud with index of the
same name, which PostgreSQL won't allow (hence the "relation fki_
already exists).

I see one main solution to it: disallow the automatic index creation if
there is no name given to the foreign key. I'll write a patch for this,
but if you see a better way to deal with this, tell us.

--
Guillaume
http://www.postgresql.fr
http://dalibo.com

In response to

Responses

Browse pgadmin-support by date

  From Date Subject
Next Message Magnus Hagander 2010-11-20 11:27:02 Re: Foreign key UI bug
Previous Message Aren Cambre 2010-11-20 04:05:05 Two feature requests