Skip to content

Instantly share code, notes, and snippets.

@foxnewsnetwork
Created May 19, 2015 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxnewsnetwork/622810064e340fd73ed4 to your computer and use it in GitHub Desktop.
Save foxnewsnetwork/622810064e340fd73ed4 to your computer and use it in GitHub Desktop.
Switching to Elixir Ecto from rails activerecord and dealing with timestamps

TL;DR, ActiveRecord's timestamps macro creates :created_at and :updated_at but Ecto's timestamps creates :inserted_at and :updated_at. If you already have a database setup and now want to switch from ActiveRecord rails to Ecto Elixir, you'll no doubt run into the following error:

(1054): Unknown column 'a0.inserted_at' in 'field list'

You can resolve this by going into your model file and making the following edit:

# models/appointments.ex
defmodule Appointment do
  ...
  schema "appointments" do
    ...
    timestamps inserted_at: :created_at
  end
  ...
end

This way, Ecto knows your inserted_at is called created_at as per rails convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment