2

I'm getting the following error when I try to create a new venue that is location aware.

ActiveRecord::StatementInvalid: PG::Error: ERROR:  new row for relation "venues" violates check constraint "enforce_srid_latlon"

This is the method I follow to recreate the error.

v = Venue.create(:latlon => "POINT (43.245332 -85.4352332)")
v.save

I did notice that in my migrations, I did not set the :geographic => true property for t.point :latlon. Could that be what's causing my problems? If so, how do I set that flag to true on a column that already contains data?

codabrink
  • 140
  • 1
  • 7

2 Answers2

3

As the (Postgres) error message tells you, the new row would violate the check constraint enforce_srid_latlon.

Look at the definition of the check constraint and you will have your answer. In psql you can use:

\d venues

Or you can use this SQL query from any client:

SELECT r.conname, pg_catalog.pg_get_constraintdef(r.oid, true)
FROM   pg_catalog.pg_constraint r
WHERE  r.conrelid = 'venues'::regclass
AND    r.contype = 'c'
ORDER  BY 1;

Or you can use a GUI like pgAdmin.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
1

The simplest way to set your SRID is to prefix the WKT into EWKT (extended well-known text):

v = Venue.create(:latlon => "SRID=4326;POINT (43.245332 -85.4352332)")

I'm using SRID=4326, since it looks like you have WGS84 latitude/longitude coordinates, which is typical.

Mike T
  • 41,085
  • 18
  • 152
  • 203