Skip to content

Data migration object create methods not recognizing the proper primary key automatically. Primary key must be specified. #293

@tglover-primexinc

Description

@tglover-primexinc

When creating an object in a data migration, it attempts to set the primary key ID to be 1, instead of the next available key in the sequence. Simultaneous runs will version it up from 1 to 2, etc. but it should be checking the existing database where there are 40 records, and set the primary key to 41.

StandardError: An error has occurred, this and all later migrations canceled:
PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "chip_architectures_pkey"
DETAIL:  Key (id)=(1) already exists.

Is there something I need to do in configuration to get the migrations to recognize the common primary key authority like it would in regular migration files?

I'm having to add a hack to manually version up the id when creating an object:
id: Model.maximum(:id).to_i.next

It seems that I shouldn't need to do this and it should be assigned automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions