Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgrex.Error: ERROR (undefined_object): type "geometry" does not exist #15

Closed
andreapavoni opened this issue May 15, 2015 · 4 comments

Comments

@andreapavoni
Copy link

Hi there, I'm new to Elixir world :)

I'm trying to play with Phoenix framework, Ecto and Postgres. I needed geolocation and I've found this package. I've added dependencies to mix.exs:

  defp deps do
    [{:phoenix, "~> 0.13"},
     {:phoenix_ecto, "~> 0.4"},
     {:geo, "~> 0.12.0"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 1.0"},
     {:phoenix_live_reload, "~> 0.4", only: :dev},
     {:cowboy, "~> 1.0"}]
  end

configured database:

config :baho_api, BahoApi.Repo,
  database: "baho_api_dev",
  adapter: Ecto.Adapters.Postgres,
  extensions: [{Geo.PostGIS, library: Geo}],
  username: "USER",
  password: "SECRET",
  size: 10 # The amount of database connections in the pool

then I've created the migration migration:

  def change do
    create table(:mytable) do
      add :place, :geometry
      timestamps
    end
  end

but when I run mix ecto.migrate I get this error:

** (Postgrex.Error) ERROR (undefined_object): type "geometry" does not exist
    (ecto) lib/ecto/adapters/sql/worker.ex:26: Ecto.Adapters.SQL.Worker.query!/4
    (ecto) lib/ecto/adapters/sql.ex:187: Ecto.Adapters.SQL.use_worker/3
    (ecto) lib/ecto/adapters/postgres.ex:59: Ecto.Adapters.Postgres.execute_ddl/3
    (stdlib) timer.erl:194: :timer.tc/3
    (ecto) lib/ecto/migration/runner.ex:22: Ecto.Migration.Runner.run/6
    (ecto) lib/ecto/migrator.ex:113: Ecto.Migrator.attempt/6
    (ecto) lib/ecto/migrator.ex:63: anonymous fn/4 in Ecto.Migrator.do_up/4
    (ecto) lib/ecto/adapters/sql.ex:442: Ecto.Adapters.SQL.transaction/3

I'm almost sure I'm missing something right away, can someone help me with this problem?

thanks in advance :)

@andreapavoni
Copy link
Author

as an update, I've also tried to use the git master (and done the new changes to configs), but I get the same error.

@bryanjos
Copy link
Contributor

From the error it looks like it could be that postgis isn't enabled for the database you are using. In psql or whatever admin app you are using for postgres you should run the command 'create extension postgis;' and then try again. I think that's the command. I'm going off memory at the moment.

@andreapavoni
Copy link
Author

Thank you for the hint! :-)

for reference, here's a solution (and the right postgres syntax), I've created a migration:

defmodule MyApp.Repo.Migrations.EnablePostgis do
  use Ecto.Migration

  def up do
    execute "CREATE EXTENSION IF NOT EXISTS postgis"
  end

  def down do
    execute "DROP EXTENSION IF EXISTS postgis"
  end
end

I'd suggest to put this in the README, it might be useful for others :P

@bryanjos
Copy link
Contributor

No problem. And yes, I should add that to the docs. I should also start doing it in a migration myself. I've been doing it the old fashioned way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants