2
votes

I am new over Elixir and Phoenix. I was trying to run migration for few migration files with mix ecto.migrate but it throws this error ,

18:27:24.471 [info]  == Running FatLobster.Repo.Migrations.CreateRecipeTable.change/0 forward
** (Ecto.MigrationError) cannot execute command outside of block
    (ecto) lib/ecto/migration/runner.ex:139: Ecto.Migration.Runner.subcommand/1
    _build/dev/lib/fat_lobster/priv/repo/migrations/20160423115340_create_recipe_table.exs:5: FatLobster.Repo.Migrations.CreateRecipeTable.change/0
    (stdlib) timer.erl:197: :timer.tc/3
    (ecto) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/6
    (ecto) lib/ecto/migrator.ex:121: Ecto.Migrator.attempt/6
    (ecto) lib/ecto/migrator.ex:71: anonymous fn/4 in Ecto.Migrator.do_up/4
    (ecto) lib/ecto/pool.ex:292: Ecto.Pool.with_rollback/3
    (ecto) lib/ecto/adapters/sql.ex:582: Ecto.Adapters.SQL.transaction/8
    (ecto) lib/ecto/pool.ex:244: Ecto.Pool.outer_transaction/6
    (ecto) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.transaction/3
    (ecto) lib/ecto/migrator.ex:226: anonymous fn/4 in Ecto.Migrator.migrate/4
    (elixir) lib/enum.ex:1088: Enum."-map/2-lists^map/1-0-"/2
    (ecto) lib/mix/tasks/ecto.migrate.ex:63: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
    (elixir) lib/enum.ex:604: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:604: Enum.each/2
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
    (elixir) lib/code.ex:363: Code.require_file/2

And here is the Migration ,

defmodule FatLobster.Repo.Migrations.CreateRecipeTable do
  use Ecto.Migration

  def change do
    add :recipe_title, :string
    add :recipe_description,  :string

    add :cover_img, :string
    add :picture_one, :string
    add :picture_two, :string
    add :picture_three, :string

    add :user_id, :integer
    add :upvote_count, :integer
    add :downvote_count, :integer

    timestamps
  end
end

Now , what is really going wrong here? what I am really missing ? should I look for something specific ?

1
Could you post the "CreateRecipeTable" migration's source code? - Dogbert
@Dogbert hi , I just edited the question . - Mahabub Islam Prio
I can reproduce the error... ** (FunctionClauseError) no function clause matching in Ecto.Migration.table/2 (ecto) lib/ecto/migration.ex:400: Ecto.Migration.table("recipes", []) _build/dev/lib/my_app/priv/repo/migrations/20160423173600_create_recipe.exs:5: MyApp.Repo.Migrations.CreateRecipe.change/0 ... by using a string instead of an atom. That is, you may have had create table("recipes") do, and it should be create table(:recipes) do. - Wendy Smoak

1 Answers

6
votes

You are missing the create table(...) block:

defmodule FatLobster.Repo.Migrations.CreateRecipeTable do
    use Ecto.Migration

    def change do
        create table(:recipes) do
            add :recipe_title, :string
            add :recipe_description,  :text
            add :cover_img, :string
            add :picture_one, :string
            add :picture_two, :string
            add :picture_three, :string

            add :user_id, :integer
            add :upvote_count, :integer
            add :downvote_count, :integer

            timestamps
        end
    end
end

More info here: https://hexdocs.pm/ecto/Ecto.Migration.html#create/1