Hello all, I recently installed the asdf package to handle version management on my machine. When I downloaded the package it took some work to get all my projects up and running. I have them all going except for one. when I try to run mix phx.server I get this error.
[error] Could not create schema migrations table. This error usually happens due to the following:
* The database does not exist
* The "schema_migrations" table, which Ecto uses for managing
migrations, was defined by another library
* There is a deadlock while migrating (such as using concurrent
indexes with a migration_lock)
To fix the first issue, run "mix ecto.create".
To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create". Alternatively you may configure Ecto to use
another table for managing migrations:
config :beswick, Beswick.Repo,
migration_source: "some_other_table_for_schema_migrations"
The full error report is shown below.
[info] Application beswick exited: exited in: Beswick.Application.start(:normal, [])
** (EXIT) an exception was raised:
** (RuntimeError) could not lookup Beswick.Repo because it was not started or it does not exist
(elixir) lib/keyword.ex:504: Keyword.delete_key/3
(elixir) lib/keyword.ex:501: Keyword.delete_key/3
(elixir) lib/keyword.ex:501: Keyword.delete_key/3
(elixir) lib/keyword.ex:493: Keyword.put/3
(beswick) lib/beswick/repo.ex:11: Beswick.Repo.init/2
(ecto) lib/ecto/repo/supervisor.ex:24: Ecto.Repo.Supervisor.runtime_config/4
(beswick) lib/beswick/repo.ex:2: Beswick.Repo.config/0
(ecto_sql) lib/ecto/migrator.ex:576: Ecto.Migrator.verbose_schema_migration/3
(ecto_sql) lib/ecto/migrator.ex:411: Ecto.Migrator.lock_for_migrations/3
(ecto_sql) lib/ecto/migrator.ex:335: Ecto.Migrator.run/4
(beswick) lib/beswick/application.ex:30: Beswick.Application.start/2
(kernel) application_master.erl:277: :application_master.start_it_old/4
** (Mix) Could not start application beswick: exited in: Beswick.Application.start(:normal, [])
** (EXIT) an exception was raised:
** (RuntimeError) could not lookup Beswick.Repo because it was not started or it does not exist
(elixir) lib/keyword.ex:504: Keyword.delete_key/3
(elixir) lib/keyword.ex:501: Keyword.delete_key/3
(elixir) lib/keyword.ex:501: Keyword.delete_key/3
(elixir) lib/keyword.ex:493: Keyword.put/3
(beswick) lib/beswick/repo.ex:11: Beswick.Repo.init/2
(ecto) lib/ecto/repo/supervisor.ex:24: Ecto.Repo.Supervisor.runtime_config/4
(beswick) lib/beswick/repo.ex:2: Beswick.Repo.config/0
(ecto_sql) lib/ecto/migrator.ex:576: Ecto.Migrator.verbose_schema_migration/3
(ecto_sql) lib/ecto/migrator.ex:411: Ecto.Migrator.lock_for_migrations/3
(ecto_sql) lib/ecto/migrator.ex:335: Ecto.Migrator.run/4
(beswick) lib/beswick/application.ex:30: Beswick.Application.start/2
(kernel) application_master.erl:277: :application_master.start_it_old/4
I know this is a common error that I have seen a hundred times, but this time it is different. The database exists, I have reset it a bunch of times and run my migrations, but my app still cant seem to find the database since I started using asdf.
I have also deleted my build running rm -rf _build deps but with no luck.
on asdf I am running
elixir 1.6.6 (set by /Users/jacksobocinski/bowst/product-manager/.tool-versions)
erlang 21.3 (set by /Users/jacksobocinski/bowst/product-manager/.tool-versions)
along with {:phoenix, "~> 1.4.0"} {:plug_cowboy, "~> 2.0"} {:ecto_sql, "~> 3.0"}
mix ecto.drop will drop your current database
mix ecto.create will create a new database from scratch
mix ecto.migrate will build all your schema and migrations
You should be good to go
If not try to look in your ./config/dev.exs and verify your database credentials
For me these commands worked in an umbrella project
The only change ive made was downloading asdf. Postgres is running and when I psql in I can see the database for this app is there. I am also surprised as to why this is happening, Ive gotten this error before but its always been for the obvious reasons.
Ive tried all these approaches, my database is all set up right and running the following commands dont change anything. Ive been running this app for over a year and I havent changed anything about my database config so all that seems fine to me. But this is what it looks like if that helps
Yes the contents get dropped. All the database commands work as expected, I can drop, create, and migrate with no errors. The problem comes when I try to run the app.
OK then find application.ex it’s somewhere in lib there you should have the Repo in children map as a supervisor
Something like this:
defmodule ElixirApp.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Starts a worker by calling: ElixirApp.Worker.start_link(arg)
# {ElixirApp.Worker, arg},
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: ElixirApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
Sorry for the confusion, This is not an umbrella app. when I say other apps I just mean other phoenix projects on my machine.
Basically in application.ex I have this
def start(_type, _args) do
import Supervisor.Spec
# Define workers and child supervisors to be supervised
children = [
# Start the Ecto repository
supervisor(Beswick.Repo, []),
# Start the endpoint when the application starts
supervisor(BeswickWeb.Endpoint, []),
# Start your own worker by calling: Beswick.Worker.start_link(arg1, arg2, arg3)
# worker(Beswick.Worker, [arg1, arg2, arg3]),
# supervisor(Beswick.ImportSupervisor.start_link([]),[], [name: Beswick.ImportSupervisor])
Beswick.SchedulAvailabilityImport,
supervisor(Beswick.ImportSupervisor, [[]])
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Beswick.Supervisor]
start_result = Supervisor.start_link(children, opts)
# migrate app on start
path = Application.app_dir(:beswick, "priv/repo/migrations")
Ecto.Migrator.run(Beswick.Repo, path, :up, all: true)
start_result
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
BeswickWeb.Endpoint.config_change(changed, removed)
:ok
end
end
Which I believe is all correct unless something has changed about the syntax in this file.
Please do me a favor and tripple check if the owner of the database is correct, and also do a permission check on your current user, is it allowed to read the schema_migrations table?
Does that table actually exist after running ecto.create or at least after running ecto.migrate?
And also as a matter of precaution: What version of ecto and ecto_sql are in your mix.lock?
I am not exactly sure how to tell if any process is using the database but I feel like restarting my computer would kill that process. I tried restarting and updating postgres with no luck :\