0
To nie jest błąd

Primary key generation creates errors

Rob Hill 6 miesięcy temu Ostatnio zmodyfikowane przez Adam Mościcki 5 miesięcy temu 1

I have two tables, both with a column named "id" that is a SERIAL and the primary key of each.

The SQL that is generated creates a constraint to declare the primary key:

CONSTRAINT id PRIMARY KEY (id)

Using the generated SQL, the first table is created successfully.

The second table fails with the following error:

   relation "id" already exists

The constraint name must be unique.

A better solution would be to suffix the primary key column with "PRIMARY KEY".

Alternatively, if you must create a constraint, prefix the name with the table name.

To nie jest błąd

Hello Rob,

You have set the same primary key name for two different tables. 
If you leave a primary key's name empty, the constraint name will be automatically generated.
An example here:



Hope this helps,
Adam