Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tglover-primexinc opened this issue Nov 8, 2023 · 1 comment

Comments

@tglover-primexinc
Copy link

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.

@tglover-primexinc
Copy link
Author

Apologies. This was due to a special circumstance and not related to the gem. I was seeding with static primary and foreign keys, and that created the sequence table to become out of sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant