V2.7 upgrade: uniqueness violations

So, after getting a semi-working upgrade to v2.7 going, my site loads but I can’t post (or do virtually anything else) because uniqueness constraints are getting violated all over the place. For example, when I post, I get this in the error logs:

Feb 27 15:41:12 ip-172-31-40-19 bundle[13429]: 2019-02-27T15:41:12.146Z 13429 TID-gnci76i3l WARN: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "conversations_pkey"
Feb 27 15:41:12 ip-172-31-40-19 bundle[13429]: DETAIL:  Key (id)=(39210) already exists.
Feb 27 15:41:12 ip-172-31-40-19 bundle[13429]: : INSERT INTO "conversations" ("uri", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"

This is happening with all sorts of various actions I take on all sorts of various uniqueness constraints. It’s almost like there’s some sort of cache of what the next id value should be and it’s out of track with the database.

I’m not 100% sure how or why this happened, but I was able to resolve it by getting bundle to run a little rails code for me:

ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.reset_pk_sequence!(t) }