PG::ForeignKeyViolation: on upgrade past v1.4.1

Dear Mastodon Community,

I noticed strange behaviour after upgrading to v1.4.1.

When looking at my home tab, I saw several boosted toots, the userpics were not downloaded, so weren’t the following toots of these accounts.

Going through the accounts I saw /web/accounts/3180 having no pic or even one toot federated to me, however /web/accounts/3189 works with federating to me again. This happens for several federating instances.
Third example /web/accounts/3342 doesn’t work, only the boosted toot gets loaded, no pic, no further messages.

I heard about some streaming fix in later versions so I upgraded to the newest commit to see if it fixes it, but it unfortunately doesn’t.

On upgrading I did a db migration / asset recreation to make sure everything is working as it should,
however I was given an error on db migration:
Migrating to AddForeignKeysForAccounts (20170604144747)
== 20170604144747 AddForeignKeysForAccounts: migrating ========================
– add_foreign_key(:statuses, :accounts, {:on_delete=>:cascade})
-> 0.0908s
– add_foreign_key(:statuses, :accounts, {:column=>:in_reply_to_account_id, :on_delete=>:nullify})
-> 0.0154s
– add_foreign_key(:statuses, :statuses, {:column=>:in_reply_to_id, :on_delete=>:nullify})
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::ForeignKeyViolation: ERROR: Inserting or updating in table »statuses« violates foreign key constraint »fk_rails_94a6f70399«
DETAIL: Key (in_reply_to_id)=(1898) is not ofund in table »statuses«
: ALTER TABLE “statuses” ADD CONSTRAINT "fk_rails_94a6f70399"
FOREIGN KEY (“in_reply_to_id”)
REFERENCES “statuses” (“id”)

(I translated the error partially as it was given out in german)

Any help on this would be appreciated, thanks!

Best wishes,

Foreign keys were introduced and the database might have been to be cleaned up of duplicates. Please try running mastodon:prepare_for_foreign_keys task - it should help.

Besides, you need to check if you are running clean source tree and the version you are expecting… foreign keys were introduced after 1.4.1

More info

That did the trick, thanks

1 Like