Restore fails - could not create unique index

This issue with the incoming_referers table has come up a few times recently. I’m not sure why that particular table is causing problems, but it seems likely that the issues are related. Maybe someone else on the Discourse team will have ideas about what could be causing the duplicate records to be created.

Do you still have access to the site that you created the backup file on? If so, the fix is to delete the duplicate record from the database and then create a new backup file. To do that, you would SSH into the old server and cd to the /var/discourse directory:

 cd /var/discourse

Then run

./launcher enter app

Then enter the Rails console with

rails c

You should then see a prompt that looks similar to this:

[1] pry(main)>

Try running the following command from the Rails console and let us know what it returns:

IncomingReferer.where(path: "/m/search")

It should return an array with two or more records.

2 Likes