Today I Learned

Inserting data in migrations

When you encounter a problem with inserting data in migrations and your Repo is not aware about created table yet, you need to use flush()

# ...
  def up do
    create table("players") do
      add :name, :varchar, null: false
      add :color, :varchar, null: false
      add :avatar, :varchar, null: false
    end

    create index("players", [:name], unique: true)

    flush() # 👷

    Repo.insert!(%Player{...})
  end
# ...