postgresql - 无法为 Elixir 的 Phoenix 创建新的 Postgres 表

标签 postgresql elixir phoenix-framework

我正在关注 https://robots.thoughtbot.com/testing-a-phoenix-elixir-json-api

我正在尝试创建一个迁移。

当我运行 mix ecto.migrate 时,我得到:

/code/mpa:.mix ecto.migrate
** (exit) exited in: GenServer.call(#PID<0.141.0>, {:query, "CREATE TABLE IF NOT EXISTS \"schema_migrations\" (\"version\" bigint PRIMARY KEY, \"inserted_at\" timestamp)", []}, :infinity)
    ** (EXIT) %Postgrex.Error{message: nil, postgres: %{code: :invalid_catalog_name, file: "postinit.c", line: "794", message: "database \"mpa_dev\" does not exist", pg_code: "3D000", routine: "InitPostgres", severity: "FATAL"}}
    (elixir) lib/gen_server.ex:356: GenServer.call/3
    (postgrex) lib/postgrex/connection.ex:102: Postgrex.Connection.query/4
    (ecto) lib/ecto/adapters/postgres/connection.ex:31: Ecto.Adapters.Postgres.Connection.query/4
    (ecto) lib/ecto/adapters/sql.ex:228: Ecto.Adapters.SQL.query/7
    (ecto) lib/ecto/pool.ex:159: Ecto.Pool.do_run/4
    (ecto) lib/ecto/adapters/sql.ex:216: Ecto.Adapters.SQL.query/6
    (ecto) lib/ecto/adapters/sql.ex:191: Ecto.Adapters.SQL.query/5
    (elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3

但我刚刚创建了表格。 checkin Postgres:

~:.psql -d template1
psql (9.4.4)
Type "help" for help.

template1=# CREATE TABLE mpa_dev();
ERROR:  relation "mpa_dev" already exists
template1=#

为什么会出现此错误以及如何创建表格?

最佳答案

从错误消息中可以清楚地看出:

"database \"mpa_dev\" does not exist"

您需要创建一个名为“mpa_dev”的数据库:

createdb mpa_dev

然后运行

mix ecto.migrate

如果您希望数据库名称为 template1(如您在示例中提到的),请在 config/dev.exs 中编辑数据库名称并运行 mix ecto.migrate 再次。

关于postgresql - 无法为 Elixir 的 Phoenix 创建新的 Postgres 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32020684/

相关文章:

sql - 我如何将条件按时间段分组?

Entity Framework 中的 Postgresql 表继承

Django-Postgres : length of CharField as primary key

elixir - 是否可以通过字符串或符号动态访问模块?

elixir - Phoenix Server 运行时如何在 Controller 中记录某些内容?

postgresql - 仅在 phoenix、ecto 和 postgres 中附加数据

postgresql - 加入对 jsonb 字段的查询

erlang - 如何获取Elixir中变量的存储位置?

postgresql - Phoenix/Elixir - 时间戳不存在,扩展为 timestamps()

elixir - 如何在 Phoenix LiveView 中测试 handle_info/2?