Adding binary id to phoenix apps

jrowah

jrowah

Created 5 months ago

When generating a new phoenix application, you can pass the –binary-id flag to get uuids. However, it is possible to forget this and when you do you can add this using two routes, one is longer where you edit every schema adding @primary_key {:id, :binary_id, autogenerate: true} and @foreign_key_type :binary_id. Or the shortest way out is just edit your config.exs

config :my_app,
  ecto_repos: [MyApp.Repo],
  generators: [timestamp_type: :utc_datetime, binary_id: true] #add binary_id and set it to true

then reset your db and that will be it. Note that this works if you still have the ability to reset your database.