pgiesin

pgiesin

This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.

Dependencies

{:comeonin, "~> 5.1"},
{:postgrex, "~> 0.14.1"},
{:ecto_sql, "~> 3.0"},

Repo

defmodule AccountService.Repo do
    use Ecto.Repo, 
        otp_app: :account_service,
        adapter: Ecto.Adapters.Postgres
end

Config

config :account_service, AccountService.Repo,
    database: "worksolvr",
    username: "postgres",
    password: "REDACTED",
    hostname: "localhost"

When i attempt to run mix ecto.migrate I receive:

[error] GenServer #PID<0.202.0> terminating
** (RuntimeError) connect raised KeyError exception: key :database not found.The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true if you wish to see all of the details
    (elixir) lib/keyword.ex:389: Keyword.fetch!/2
    (postgrex) lib/postgrex/protocol.ex:90: Postgrex.Protocol.connect/1
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

Thanks,
Peter

Showing Posts 22 to 13

tenzil

tenzil

Finally i did it, i deployed it in heroku. first thing i scratched the previous deploy setup and added them again, second my prod.secret.exs had config :myapp, MyAppWeb.Repo which was not commented.
Issue deploying to gigalixir - (RuntimeError) connect raised KeyError exception: key :database not found , helped when i revisited this issue.
Thanks folks.

tenzil

tenzil

ohh, okay. I have not updated the config, as i was referring the old app (1.8) at first . when it didn’t workout i did few changes for the new app(1.9) then finally the app got deployed, post deployment i ran mix ecto.setup then found out this database not found error.

One of the referred blogs.
https://github.com/dwyl/learn-heroku/blob/master/elixir-phoenix-app-deployment.md

I will scratch it out and try a new deployment specific to 1.9. Will update here once thats done.
Thanks guys :+1:

NobbZ

NobbZ

Okay, one question answered, last one was if you have properly updated the config into the new format.

It won’t work when you mixed things up. Either fully use 1.8 syntax or 1.9.

tenzil

tenzil

No, it doesn’t use releases, I have web: MIX_ENV=prod mix phx.server in my procfile

NobbZ

NobbZ

That does not answer any of my questions…

Does your buildpack use releases or mix phx.server?

Have you properly updated your config files for 1.9?

dimitarvp

dimitarvp

I should have recommended that earlier, but I assumed you had it somewhere.

Basically, you can’t go without that. You need a database name in which your app to persist stuff! :slight_smile:

tenzil

tenzil

As its an heroku app, i just do
git push heroku master this does the trick.

And @dimitarvp, i haven’t tried that database: "your_db_name_here"

NobbZ

NobbZ

How do you deploy? And have you updated your config from Mix.Config to Config, and especially have you done that consequently for all files in config?

dimitarvp

dimitarvp

BTW, do you also have this in your config file?

config :myapp, ecto_repos: [MyApp.Repo]

Additionally, have you tried actually adding the database key?

config :MyApp, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5"),
  ssl: true,
  url: System.get_env("DATABASE_URL"),
  show_sensitive_data_on_connection_error: true,
+ database: "your_db_name_here"
dimitarvp

dimitarvp

At this point I recommend you generate a new Phoenix project with mix and using the proper switches (namely you want an Ecto Repo, use the same module and app name as your current project etc.) and then just search for the differences between your project and the freshly generated one.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews