首页 > 解决方案 > “找不到#PID<0.94.0> 的迁移运行程序进程”是什么意思以响应混合ecto.migrate?

问题描述

我正在阅读有关 Phoenix 上下文的指南(https://hexdocs.pm/phoenix/contexts.html#thinking-about-design),在您运行的部分

mix ecto.gen.migration add_author_id_to_pages

然后在迁移中添加一些东西。这是完整的输出:

$ mix ecto.migrate
** (RuntimeError) could not find migration runner process for #PID<0.94.0>
    (ecto_sql 3.5.3) lib/ecto/migration/runner.ex:100: Ecto.Migration.Runner.prefix/0
    (ecto_sql 3.5.3) lib/ecto/migration.ex:1261: Ecto.Migration.__prefix__/1
    (ecto_sql 3.5.3) lib/ecto/migration.ex:525: Ecto.Migration.create/1
    priv/repo/migrations/20210120060822_add_author_id_to_pages.exs:10: (module)
    (stdlib 3.13.2) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir 1.11.2) lib/code.ex:1172: Code.compile_file/2
    (ecto_sql 3.5.3) lib/ecto/migrator.ex:626: Ecto.Migrator.load_migration!/1
    (elixir 1.11.2) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.11.2) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
    (ecto_sql 3.5.3) lib/ecto/migrator.ex:430: Ecto.Migrator.run/4
    (ecto_sql 3.5.3) lib/ecto/migrator.ex:145: Ecto.Migrator.with_repo/3

这是迁移:

defmodule Hello.Repo.Migrations.AddAuthorIdToPages do
  use Ecto.Migration

  def change do
    alter table(:pages) do
      add :author_id, references(:authors, on_delete: :delete_all), null: false
    end
  end

  create index(:pages, [:author_id])
end

标签: elixirphoenix-frameworkecto

解决方案


这是因为我在街区create index外接到了电话。def change将其更改为此有效:

defmodule Hello.Repo.Migrations.AddAuthorIdToPages do
  use Ecto.Migration

  def change do
    alter table(:pages) do
      add :author_id, references(:authors, on_delete: :delete_all), null: false
    end
    create index(:pages, [:author_id])
  end
end


推荐阅读