Search code examples
postgresqldelphifiredacdelphi-10.4-sydney

Migrating an AnyDAC app to FireDAC fails on the AutoInc fields


I have migrated an AnyDAC app to FireDAC and I can't get to work its Autoinc fields.

The ID field (primary key) has been defined on Postgre SQL as default to nextval('llistapanelspuzzle_id_seq'::regclass), BIGSERIAL, so the server automatically sets its values.

The column was recognized by AnyDAC as an TAutoincField and worked correctly, but when I now open that table on FireDAC it fails saying that the field found is a TLargeIntField. I change the persistent field to a TLargeIntField, but now when inserting records on Delphi, I don't get the new values from the server, it leaves the dataset with a 0 value, and when I add a second record it raises a Key Violation (two records with a 0 value on its primary key).

Do you know how to define AutoInc fields on FireDAC - PostgreSQL, when they are being recognized as LargeInt fields ?.

Update: I have added ID to the UpdateOptions.AutoIncFields, but it doesn't seem to have changed anything.

Thank you.


Solution

  • Looks like you have to activate the ExtendedMetada flag on the FDConnection in order for FireDAC to recognize automatically the PostgreSQL Autoinc columns.

    Now it works correctly.