ActiveRecord::RecordNotUnique (duplicate key value violates unique constraint). Key already exists.

Recently I was getting an issue while inserting a new record to one of the table in our database. I was getting this specific error - ActiveRecord::RecordNotUnique (PG::Error: ERROR: duplicate key value violates unique constraint "canonical_cities_pkey" DETAIL: Key (id)=(*****) already exists. Understanding the error The table currently has several thousand entities for canonical cities. But when am trying to insert a new record it builds an canonical_city record and assign it an 'id', say 111, but that 'id' already exist. The primary key which is suppose to auto-increment and generate an unique id