Error while importing topics from Flarum (users, groups import OK)

Hey folks, I’m really hoping someone can help me out with a Flarum to Discourse migration I’m working on. I’ve hacked my way through a huge amount of missing knowledge on my part, and solved a couple of errors based on assumptions the current importer appears to make (e.g. database prefixes). After all that I was able to get both Categories and Users imported! :partying_face:

But now I’m running into problems getting the actual Topics in, which are of course one of the most important things. :grinning_face_with_smiling_eyes: And unfortunately I’m finding very little on the specific error message I am getting. There is one older topic here in Meta that never got a response, so no help there. I’m hopeful I can fare better. :grin:

Here’s the full error message. The part near the bottom seems to be the pointy end. The “duplicate key value” that’s identified really seems vague, so I’m stuck. Thanks in advance for any insight you can provide!

An error occurred while loading ./script/import_scripts/flarum_import.rb.
Failure/Error: return exec_without_profiling(*args, &blk) unless SqlPatches.should_measure?

  ERROR:  current transaction is aborted, commands ignored until end of transaction block
# ./script/import_scripts/base.rb:243:in `ensure in block in all_records_exist?'
# ./script/import_scripts/base.rb:243:in `block in all_records_exist?'
# ./script/import_scripts/base.rb:224:in `all_records_exist?'
# ./script/import_scripts/flarum_import.rb:122:in `block in import_posts'
# ./script/import_scripts/base.rb:874:in `block in batches'
# ./script/import_scripts/base.rb:873:in `loop'
# ./script/import_scripts/base.rb:873:in `batches'
# ./script/import_scripts/flarum_import.rb:101:in `import_posts'
# ./script/import_scripts/flarum_import.rb:32:in `execute'
# ./script/import_scripts/base.rb:47:in `perform'
# ./script/import_scripts/flarum_import.rb:162:in `<top (required)>'
# ------------------
# --- Caused by: ---
# PG::UniqueViolation:
#   ERROR:  duplicate key value violates unique constraint "import_ids_pkey"
#   DETAIL:  Key (val)=(3) already exists.
#   ./script/import_scripts/base.rb:231:in `block in all_records_exist?'
No examples found.

Finished in 0.00004 seconds (files took 5.56 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

Sounds like a corrupt index, which is surprising. What version of postgres is this? I would likely wipe the database and try again. You’ll likely need to do it a bunch of times anyway as you debug other issues with topics.

The other option is to try to rebuild that index and delete duplicate records until it works.


Thanks Jay! I unfortunately lost this Discourse install due to, well, foolishness on my part (mishandling a virtual machine). So I can’t go back and check, nor do your recommended troubleshooting, which I feel pretty bad/dumb about. But there we have it.

What I can tell you is that I followed the Discourse Ubuntu setup instructions:

So it’d be whatever version of Postgres is installed that way. And I had tried to import a couple of times by this point, without clearing the DB in-between, so maybe that has something to do with it.

I followed the Ubuntu dev environment method rather than use the Docker approach because when I’d tried that earlier (on Digital Ocean), none of the instructions I was finding for how to do, well, anything were working because, presumably, it was inside Docker/containers and required a different approach.

I am very much operating at the limits of my understanding here, unfortunately, but it felt worth at least trying to do myself. With this big setback, and the knowledge that there are likely more troubleshooting steps ahead, I think it’s very likely time to seek professional help. So I’m off to try to get some budget for that. :grinning_face_with_smiling_eyes:

Thanks again for your help!

Perfect! There’s no reason to figure out what happened unless it happens again.

1 Like