Re: Foreign key UI bug

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
Cc: Aren Cambre <aren(at)arencambre(dot)com>, pgadmin-support(at)postgresql(dot)org
Subject: Re: Foreign key UI bug
Date: 2010-11-20 11:27:02
Message-ID: AANLkTimEbZy4=xkBX+tPjyL0-hHF+5vWeQ8QndWYevxs@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

On Sat, Nov 20, 2010 at 12:24, Guillaume Lelarge <guillaume(at)lelarge(dot)info> wrote:
> 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.

Well, you could generate the name of the FOREIGN KEY in pgadmin as
well, then you know what it'll be... Even when the user doesn't
specify one.

Another one would be to name the index fki_<tablename>_<columnname> or
something like that instead.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

In response to

Responses

Browse pgadmin-support by date

  From Date Subject
Next Message Guillaume Lelarge 2010-11-20 11:37:05 Re: Foreign key UI bug
Previous Message Guillaume Lelarge 2010-11-20 11:24:24 Re: Foreign key UI bug