Phoenix提示运行不存在的迁移 更新

问题描述

让我们描述一下问题:

  • 我使用mix phx.new创建了一个新的phoenix应用
  • 我在{dev,test}.exs内配置了数据库连接(正在映射现有数据库
  • 我使用mix phx.gen.context创建了一个上下文(创建了迁移)

我第一次尝试运行服务器,但它告诉我我尚未部署迁移。

there are pending migrations for repo: Some.Repo. 
Try running `mix ecto.migrate` in the command line to migrate it

然后我意识到我不需要它们,因为我已经有了数据库,所以我删除了迁移文件/priv/repo/migrations/*),然后再次尝试。

现在mix ecto.migrations不显示任何内容,但没有删除服务器提示。然后我发现ecto在数据库中为迁移创建了另一个表,所以我检查了它,它是空的。

我放下它并尝试再次运行服务器,但显示了相同的消息。


为确保这不是Ecto问题,我已经准备了测试并且运行正常,唯一的问题是运行服务器时显示的迁移提示


自从我计划使用GraphQL之后,我还没有任何端点,因为我已经验证了模型可以正常工作但是该消息令人困惑。

该迁移是否存在任何隐藏文件?或者我还缺少其他东西吗?

Stacktrace:

[error] #PID<0.451.0> running Some.Endpoint (connection #PID<0.449.0>,stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (Phoenix.Ecto.PendingMigrationError) there are pending migrations for repo: Some.Repo. Try running `mix ecto.migrate` in the command line to migrate it
        (phoenix_ecto 4.2.1) lib/phoenix_ecto/check_repo_status.ex:67: Phoenix.Ecto.CheckRepoStatus.check_pending_migrations!/2
        (phoenix_ecto 4.2.1) lib/phoenix_ecto/check_repo_status.ex:27: anonymous fn/3 in Phoenix.Ecto.CheckRepoStatus.call/2
        ...
[error] #PID<0.454.0> running Some.Endpoint (connection #PID<0.449.0>,stream id 2) terminated
Server: localhost:4000 (http)
Request: GET /favicon.ico
** (exit) an exception was raised:
    ** (Phoenix.Ecto.PendingMigrationError) there are pending migrations for repo: Some.Repo. Try running `mix ecto.migrate` in the command line to migrate it
        (phoenix_ecto 4.2.1) lib/phoenix_ecto/check_repo_status.ex:67: Phoenix.Ecto.CheckRepoStatus.check_pending_migrations!/2
        (phoenix_ecto 4.2.1) lib/phoenix_ecto/check_repo_status.ex:27: anonymous fn/3 in Phoenix.Ecto.CheckRepoStatus.call/2
        ...

更新

经过进一步调查,该项目似乎以某种方式存储了mix phx.new.context产生的第一个迁移。

每当我重新创建数据库时,它都会提示迁移此上下文。我的项目中没有任何文件提到迁移。

解决方法

运行 mix ecto.migrations 这将显示您拥有的迁移。该列表将(希望)与 /priv/repo/migrations 中的列表匹配。 转到 _build//priv/repo/migrations 并从此处删除不在其他两个迁移列表中的文件。 它似乎对我有用

,

我遇到了这个问题,只能通过删除_build文件夹来解决此问题,没有其他办法,ecto.reset也不删除迁移表。 Elixir必须在某个地方的项目中存储一些与迁移有关的状态。

rm -rf _build/