Can't connect to database

Hi all – its me again :confused: I made a change to my .profile so as to store KOKO_SECRET there. But something else must have happened because I now get this error when I try to run the app:

(Ecto.InvalidURLError) invalid url koko_dev, host is not present

I’ve done the folllowing so far:

a) Verified that the database is up by looking at it with pgCommander and also directly on the command line with psql.

b) manually stopped and started the database.

c) retyped export DATABASE_URL='koko_dev' in profile

I am pretty sure that my code is OK – I get no error in the terminal windows that I was in and in which I have not executed source ~/.profile

So I am mystified, flummoxed and totally blocked at this point. Yikes!!!

PS. Another check:

$ psql
carlson=# \c koko_dev
You are now connected to database "koko_dev" as user "carlson".

and also

$ psql -U postgres
postgres=> \c koko_dev
You are now connected to database "koko_dev" as user "postgres".

I did the above in both the “good” and the “bad” terminal windows with the same results.

It would be helpful if you included your mix database config.

Here is what I have (I am using Phoenix 1.3rc2):

defmodule Koko.Repo do
  use Ecto.Repo, otp_app: :koko

  @doc """
  Dynamically loads the repository url from the
  DATABASE_URL environment variable.
# koko_umbrella_apps/koko/lib/koko/repo.ex

  def init(_, opts) do
    {:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
    # {:ok, Keyword.put(opts, :url, "koko_dev")}

Here is # koko_umbrella_apps/koko/config/dev.exs

use Mix.Config

# Configure your database
config :koko, Koko.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "postgres",
  database: "koko_dev",
  hostname: "localhost",
  pool_size: 10

And here is mix.exs

# koko_umbrella_apps/koko/mix.exs

defmodule Koko.Mixfile do
  use Mix.Project

  def project do
    [app: :koko,
     version: "0.0.1",
     build_path: "../../_build",
     config_path: "../../config/config.exs",
     deps_path: "../../deps",
     lockfile: "../../mix.lock",
     elixir: "~> 1.4",
     elixirc_paths: elixirc_paths(Mix.env),
     start_permanent: Mix.env == :prod,
     aliases: aliases(),
     deps: deps()]

  # Configuration for the OTP application.
  # Type `mix help` for more information.
  def application do
    [mod: {Koko.Application, []},
     extra_applications: [:logger, :runtime_tools]]

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_),     do: ["lib"]

  # Specifies your project dependencies.
  # Type `mix help deps` for examples and options.
  defp deps do
    [{:postgrex, ">= 0.0.0"},
     {:ecto, "~> 2.1"},
     {:corsica, "~> 0.5"},
     {:comeonin, "~> 2.0"},
     {:json, "~> 1.0"},
     {:joken, "~> 1.1"},
     {:secure_random, "~> 0.2"},
     { :uuid, "~> 1.1" }]

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to create, migrate and run the seeds file at once:
  #     $ mix ecto.setup
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    ["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
     "ecto.reset": ["ecto.drop", "ecto.setup"],
     "test": ["ecto.create --quiet", "ecto.migrate", "test"]]

The URL needs to be the full database url. Per the Ecto docs:



The name of your project is quite confusing to me :slight_smile:

It derives from kokoelma, Finnish for “collection”

1 Like

Thank you, I started to see Koko everywhere