Search code examples
databaseelixirecto

ecto table not being created


I run mix ecto.migrate and have this file in my migrations:

api/priv/repo/migrations/20180724182549_create_user_table.exs:

defmodule Api.Repo.Migrations.CreateUserTable do
  use Ecto.Migration

  def change do
    create table(:users) do
      add :first_name, :string
      add :last_name, :string
      add :email, :string
      add :u_id, :string
  end

  create unique_index(:users, [:u_id])
end

It does not create the user table. What could the reason be?


Solution

  • You're missing the closing end for do:

    defmodule Api.Repo.Migrations.CreateUserTable do
      use Ecto.Migration
    
      def change do
        create table(:users) do
          add :first_name, :string
          add :last_name, :string
          add :email, :string
          add :u_id, :string
        end # this was missing
      end
    
      create unique_index(:users, [:u_id])
    end