published under license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)copy! share!
posted in category Software Development & Programming / Rails ActiveRecord
posted at 24. Aug '21
Howto Fix Broken Autoincrement - Postgres PG::UniqueViolation - Duplicate Key
Error:
ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "articles_pkey")
DETAIL: Key (id)=(101) already exists.
Go to Rails console and type:
ActiveRecord::Base.connection.reset_pk_sequence!('articles')
Where the parameter is more less the name of the index (on field).
Add Comment