Activerecord::Statementinvalid. Pg Error

Pushing to Heroku - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation users does not exist

What's happening here is that you most likely have a devise_for :users in your routes.rb file, which is causing Rails to look for the Users table when it boots up, but as you haven't run your migrations yet the table can't be found.

Comment out the devise_for in your routes.rb and push to Heroku - the migrations will run, then uncomment the devise_for and push again.

In general it's better to have created the Users table first, then add devise to the model in another, later step.

ActiveRecord::StatementInvalid (PG::InsufficientPrivilege: ERROR: permission denied for relation

$ heroku pg:info
=== DATABASE_URL, HEROKU_POSTGRESQL_IVORY_URL
Plan: Hobby-dev
...
Data Size: 16.1 MB
Tables: 9
Rows: 11578/10000 (Write access revoked)
...

There is what is causing the PG::InsufficientPrivilege error. You are using a Hobby-dev plan, which limits you to 10,000 rows in your database. You currently have 11,578 rows and it has temporarily suspended your write privileges.

Per the Heroku docs:

If the number of rows still exceeds the plan capacity after 7 days,
INSERT privileges are revoked on the database. Data can still be read,
updated, or deleted from the database. This ensures that users can
bring their database into compliance and retain access to their data.

You should have actually gotten a warning email as you approached the limit. If you clean out some of the data in the DB it will automatically restore write privileges. The Hobby-basic plan (which is not free) raises your row limit to 10 million rows, so that's also an option.

ActiveRecord::StatementInvalid: PG::InternalError: ERROR: parse error - invalid geometry

You are referring to column names inside a string, so this string is used instead of the intended coordinates.

To overcome this, you would need to concatenate the text command ('point(' with the column values and at last you concatenante the end of the text command (')'). As a result, the column name is not within the single quotes anymore.

organisation.users.joins(:location)
.where("ST_DWithin(ST_GeomFromText('POINT(' || locations.longitude || ' ' || locations.latitude ||')', 4326),ST_GeomFromText('POINT(? ?)', 4326), ?)", longitude, latitude, distance)
.pluck(:id)

PostgreSQL ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: must appear in the GROUP BY

This error is due to the fact that Postgres doesn't know what to do with the due_date column. The query you have written is basically:

for each customer, show me the total sum of the balances for all their invoices, and the due date for one of their invoices.

The problem here is that in PostgreSQL you have to be explicit about which invoice you want to show the due_date of, whereas in MySQL or SQLite it will pick one (can't remember how off the top of my head). In this case I think it would make more sense to leave out the due_date from the select, otherwise use MAX(due_date) to get the most recent, or something like that.



Related Topics



Leave a reply



Submit