1
votes

Let's describe the problem:

  • I created a new phoenix app with mix phx.new
  • I configured a database connection within {dev, test}.exs (I'm mapping an existing database)
  • I created a context using mix phx.gen.context (which created a migration)

I tried running the server for the first time but it told me that I have undeployed migrations.

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

Then I realized I don't need them since I already have the database so I deleted the migration file (/priv/repo/migrations/*) and tried again.

Now mix ecto.migrations show nothing, but it did not remove the server prompt. Then I found that ecto creates an additional table in the database for the migrations so I checked it and it was empty.

I dropped it and tried running the server again but the same message was shown.


To make sure it's not an Ecto problem I've prepared tests and they run just fine, the only problem is the migration prompt shown when I run the server.


I don't have any endpoints yet since I was planning to use GraphQL after I've verified that the models are working but that message is confusing.

Are there any hidden files for that migration or am I missing something else?

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
        ...

UPDATE

After further investigation it seems that the project somehow stores the first ever migration generated by mix phx.new.context.

Whenever I re-create the database it prompts for the migration of this very context. I don't have any files mentioning that migration in my project.

2
What does Ecto.Migrator.migrations(Some.Repo) return for you?Konstantin Strukov
@KonstantinStrukov [{:down, 20201111101131, "create_person"}]bart-kosmala
As i feared this problem doesn't allow me to test the api.bart-kosmala
Did you try to find this mysterious create_person migration? Look here - to me it looks like a migration path can be configured per repo, so please check what Some.Repo.config()[:priv] gives you - chances are your migration sits somewhere in the different location...Konstantin Strukov
@KonstantinStrukov I've managed to solve this by dropping the tables and running the prompted migration. When I re-created the database afterwards it did work. I imagine though that it would be a major problem in other circumstances. Right now Some.Repo.config()[:priv] returns nil.bart-kosmala

2 Answers

5
votes

I had this problem and it was only resolved by deleting the _build folder, nothing else worked, not ecto.reset nor deleting the migrations table. Elixir must be storing some state relating to migrations in the project somewhere.

rm -rf _build/
2
votes

run mix ecto.migrations This will show you the migrations you have. This list will (hopefully) match the list in /priv/repo/migrations. Go to _build/<your_app_name>/priv/repo/migrations and delete the files from here that are not in the other two migration lists. It seems to have worked for me