Auto-increment custom primary key | Community
Skip to main content
January 28, 2019
Solved

Auto-increment custom primary key

  • January 28, 2019
  • 2 replies
  • 4715 views

I have a requirement to create a schema with a custom primary key with auto-increment functionality.

I have created  the below schema.

<element autopk="false" desc="Terms and Conditions Table" label="Terms And Conditions"

           labelSingular="Terms And Conditions" name="terms_conditions" pkSequence="auto_custerms_conditions_sequence">

    <attribute autoIncrement="true" label="Terms Key" name="terms_key" type="long"/>

    <attribute label="Terms" name="terms" type="string"/>

    <attribute label="Terms Start Date" name="terms_start_date" type="datetime"/>

    <key internal="true" name="terms_key">

      <keyfield xpath="@terms_key"/>

    </key>

  </element>

Note that I have specified autoIncrement="true" in terms_key attribute definition.

But after inserting records, the "terms_key" is not getting auto-incremented.  Is defining schema with autopk=true and leveraging campaign generated id field is the only option?

Thanks

Bharath

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jonathon_wodnicki

Hi,

Set the col to autoincrement per your rdbms. E.g. for postgres to alter your existing col, run this sql script (Administration/Configuration/SQL scripts), changing namespace to your table's namespace:

create sequence auto_custerms_conditions_sequence;

alter table namespaceterms_conditions alter iterms_key set default nextval('auto_custerms_conditions_sequence');

You should also remove superfluous pksequence and autopk attribs from the element node, and move key to the top per convention.

Thanks,

-Jon

2 replies

Jonathon_wodnicki
Community Advisor
Jonathon_wodnickiCommunity AdvisorAccepted solution
Community Advisor
January 28, 2019

Hi,

Set the col to autoincrement per your rdbms. E.g. for postgres to alter your existing col, run this sql script (Administration/Configuration/SQL scripts), changing namespace to your table's namespace:

create sequence auto_custerms_conditions_sequence;

alter table namespaceterms_conditions alter iterms_key set default nextval('auto_custerms_conditions_sequence');

You should also remove superfluous pksequence and autopk attribs from the element node, and move key to the top per convention.

Thanks,

-Jon

January 28, 2019

Thanks for your quick response. That worked.

The other workaround I tried is to delete the entire schema and recreate it. That also worked. Looks like autoIncrement=true only works if we add it while creating the scheme.

- Bharath