Metabase post migration error on postgres

Hello team ,

We have migrated metabase to a new instance, and noticing the queries are erroring out with logs on postgres container as below -

2023-08-29 11:08:30.133 UTC [33] ERROR:  constraint "fk_sandboxes_ref_permissions" for relation "sandboxes" already exists
2023-08-29 11:08:30.133 UTC [33] STATEMENT:  ALTER TABLE "public"."sandboxes" ADD CONSTRAINT "fk_sandboxes_ref_permissions" FOREIGN KEY ("permission_id") REFERENCES "public"."permissions" ("id") ON DELETE CASCADE
2023-08-29 11:08:30.139 UTC [33] ERROR:  current transaction is aborted, commands ignored until end of transaction block

Please assist on this, how can i get this resolved? The above error seems to be shutting down the connection.
I also see the reference of the failure here on github

image: metabase/metabase:v0.46.6.2
image: postgres:14.1

It’s because you reverted to an older version without restoring the backups, so now your db is on an inconsistent state. You need to fix all the errors you see in that log and then upgrade.

@Luiggi so if I take the backup again from the older instance, and restore (or first upgrade and then restore) maintaining the same version should also fix the issue right?

but on both the sides, the version for metabase/metabase:v0.46.6.2 and postgres is same, how come then it could get reverted to an older version?