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 1 to 10

scottming

scottming

Did you create the db?

mix ecto.create
schaary

schaary

I miss the line

...
config :account_service, ecto_repos: [AccountService.Repo]
...

in your config/config.ex file.

Sanjer

Sanjer

Ensure the below and give it a re-try.

STEP 1. Define the dependencies required, mix.exs

defp deps do
    [
      {:ecto_sql, "~> 3.1"},
      {:postgrex, "~> 0.14.3"}
    ]
 end

STEP 2. Get the dependencies defined above

mix deps.get

STEP 3. Configure the Repo the application

config :helloapp, ecto_repos: [HelloApp.Repo]

Note: the :helloapp must be match the app name defined in the application.ex file. In my case I have created the application using the below command

mix new hello app --app hello app --sup

STEP 4. Configure the the Repo itself defined above

config :helloapp, HelloApp.Repo,
      host: "localhost",
      port: "5432",
      database: "helloappdb",
      username: "postgres",
      password: "postgres"

STEP 4. Define the HelloApp.Repo module in repo.ex file in /lib/{app name}

defmoudle HelloApp.Repo do
use Ecto.Repo,
    otp_app: :helloapp,
    adapter: Ecto.Adapters.Postgres
end

STEP 5. Now, lets create the database

mix ecto.create

The output should be as below.

Compiling 1 file (.ex)
Generated helloapp app
The database for HelloApp.Repo has already been created.

Hope it helps somebody.

tenzil

tenzil

Hi folks, I facing the following error with heroku. in local the app connects with db and running fine, only with heroku its throwing the following error.
I am unable to execute mix ecto.setup, :worried:
i do have another app running fine in heroku, i followed the same setups but its not connecting for the new app

(KeyError) key :database not found in: [telemetry_prefix: [:mat, :repo], otp_app: :mat, timeout: 15000, pool_size: 10]
    (elixir) lib/keyword.ex:393: Keyword.fetch!/2
    lib/ecto/adapters/postgres.ex:128: Ecto.Adapters.Postgres.storage_up/1
    lib/mix/tasks/ecto.create.ex:53: anonymous fn/3 in Mix.Tasks.Ecto.Create.run/1
    (elixir) lib/enum.ex:783: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:783: Enum.each/2
    (mix) lib/mix/task.ex:331: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2

Anyone facing the same error, I even updated my postgrex in mix

dimitarvp

dimitarvp

Post your entire prod.exs (without the secrets)? Seems like a straightforward case of not having the :database configuration key in the file.

tenzil

tenzil

Heroku uses url which has database, host, user, and password. which worked fine in elixir 1.8 phoenix app but not in 1.9 phoenix app

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
dimitarvp

dimitarvp

Are you sure your app’s atom name is :MyApp and not :myapp?

Can you also show your MyAppRepo.ex file?

tenzil

tenzil

yeah its “config :myapp, MyApp.Repo”
its a typo.

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :myapp,
    adapter: Ecto.Adapters.Postgres
  use Scrivener, page_size: 10
end

This works fine in dev env (local ), but it gets deployed in heroku as well, but just not getting connected with database.

dimitarvp

dimitarvp

I am assuming you have a DATABASE_URL environment variable in your Heroku configuration?

tenzil

tenzil

yes, i do have. dont know why its not connecting :worried:

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New

Other Trending Topics Top

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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews