Haito
Haito

Reputation: 2069

Phoenix Ecto Postgres table not creating

Sup, in the first place i want you to know that I'm fresh to Phoenix Framework and Elixir. I was working my way through tutorials but I have encountered weird problem. I configured connection and everything is working. But migration files doesn't seem to be executed. I have written following file:

defmodule Hangman.Repo.Migrations.CreateWords do
  use Ecto.Migration

  def change do
    create table(:words) do
      add :content, :string

      timestamps
    end
  end
end

Which is just a simple table with one field. But Table is not being created in the Database but Ecto thinks that everything is ok:

18:22:28.669 [info]  Already up

Upvotes: 1

Views: 5128

Answers (3)

Nikos
Nikos

Reputation: 427

This look likes it's an really old issue but just for the record I think mix ecto.reset is the single command you are looking for.

Upvotes: 1

allyraza
allyraza

Reputation: 1466

Drop the database and create it again

run

mix ecto.migrate

you are good to go

Upvotes: -2

Gazler
Gazler

Reputation: 84140

This means that the migration has already been performed. There should be a table called schema_migrations in your database that stores a reference to each migration as a row in the table with the timestamp (which is the prefix for your migration filename).

When a migration has been performed, it is not possible to run it again without rolling back. You should only do this before you push your changes upstream (i.e. nobody else is depending on it).

mix ecto.rollback
mix ecto.migrate

If the above doesn't work, you can do a full reset with - this will clear any data in your database:

mix do ecto.drop, ecto.create, ecto.migrate

Upvotes: 17

Related Questions