Ecto.StaleEntryError on update

Sometimes I get (Ecto.StaleEntryError) attempted to update a stale struct

when I try to update a record. I haven't found a recipe to avoid this in the Ecto docs, so what should I do to avoid it?

PS I am using PostgreSQL 9.6 via Postgrex, Ecto 2.1.3.

+3


source to share


1 answer


It looks like you are pulling the schema from the database and updating it after it has been updated somewhere else in your application. Do you choose, hang on to it and update later? If so, select, change and update.

To the right of the Ecto docs:



When a conflict happens (a record which has been previously fetched is
being updated, but that same record has been modified since it was
fetched), an `Ecto.StaleEntryError` exception is raised.

      

+4


source







All Articles