ijt*_*ijt 3 elixir ecto phoenix-framework
我正在阅读有关 Phoenix 上下文的指南 ( https://hexdocs.pm/phoenix/contexts.html#thinking-about-design ),在您运行的部分
mix ecto.gen.migration add_author_id_to_pages
Run Code Online (Sandbox Code Playgroud)
然后在迁移中添加一些东西。这是完整的输出:
$ 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
Run Code Online (Sandbox Code Playgroud)
这是迁移:
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
Run Code Online (Sandbox Code Playgroud)
那是因为我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
Run Code Online (Sandbox Code Playgroud)