Sometimes Updating some records by Repo.insert_all with on_conflict: :replace_all will not work properly on MySQL5.7 | Elixir /Phoenix

Photo by Artur Matosyan on Unsplash

When you want to upsert a record, you may want to use Repo.insert with on_conflict::replace_all. Me, too. However, I really DO NOT RECOMMEND this, If you are using MySQL 5.7.

The reason is here. MySQL5.7 has a bug for “insert on duplicate key”. Repo.insert_all with on_conflict::replace_all will use “insert on duplicate key”, so sometimes we will see the command won’t work which means an error comes.

I did not see any errors for that as long as I work with my local PC, but on my Production with the Aurora Instance.

So, I rewrite all of my codes for on_conflict::replace_all. Now, I just update records by Repo.update.

--

--