We are using rails (4.0.4), ruby (2.0.0p247) and activerecord-postgis-adapter (0.6.5) and singular table names set in ./config/environment.rb (ActiveRecord::Base.pluralize_table_names = false)
This works great in development and test environments.
In the production environment it works for every table but one, project. For this table we are seeing an error in the controller index.
I regenerated the scaffolding and was able to pinpoint the problem the this lin in the project_controllers:
set_rgeo_factory_for_column(:location, RGeo::Geographic.spherical_factory(:srid => 4326))
The error is:
E, [2014-04-11T10:23:09.543299 #10740] ERROR -- : PG::UndefinedTable: ERROR: relation "projects" does not exist
LINE 5: WHERE a.attrelid = '"projects"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"projects"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
I, [2014-04-11T10:23:09.543625 #10740] INFO -- : Completed 500 Internal Server Error in 7ms
F, [2014-04-11T10:23:09.545403 #10740] FATAL -- :
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "projects" does not exist
LINE 5: WHERE a.attrelid = '"projects"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"projects"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
): app/controllers/projects_controller.rb:11:in `index'
Seems really odd it works in every other environment and in production it only fails for one table, as well as associated tables.
Any suggestion appreciated.
I found two solutions:
remove set_rgeo_factory_for_column from the model, I was using the default factory anyways
Explicitly specify the table name, self.table_name. This is odd since i set ActiveRecord::Base.pluralize_table_names = false
Related
I used the command:
$ rails g model Equipment
and rails performed the following:
invoke active_record
create db/migrate/20160822040448_create_equipment.rb
create app/models/equipment.rb
invoke test_unit
create test/models/equipment_test.rb
create test/fixtures/equipment.yml
As you can see, the migration is singular! So I renamed the migration file and the table name as follows:
class CreateEquipments < ActiveRecord::Migration
def change
create_table :equipments do |t|
# ...
end
end
end
Now, after running $ rake db:migrate starting Rail's console $ rails c, it errors out saying it cannot find the table when I try to initiate an Equipment:
>> Equipment.new
PG::UndefinedTable: ERROR: relation "equipment" does not exist
LINE 5: WHERE a.attrelid = '"equipment"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"equipment"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "equipment" does not exist
LINE 5: WHERE a.attrelid = '"equipment"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"equipment"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
I was able to patch it up by adding the following line to the model:
class Equipment < ActiveRecord::Base
self.table_name = 'equipments'
# ...
end
but, although that fixes the issue, I want to know what's causing the problem to begin with.
Final Note: I tried running #pluralize method on the console, and it wouldn't pluralize the string 'Equipment' in there either:
>> 'Equipment'.pluralize
=> "Equipment"
>> 'door'.pluralize
=> "doors"
Equipment does not have a plural
http://www.learnersdictionary.com/qa/equipments-equipment-noncount-mass-noun-singular-plural
This is expected behaviour for such words.
I just upgraded my Gitlab Omnibus install from 7.3 to 7.9.1, and now rather than showing a login page, Gitlab just shows a 500 error page (see below)
I also noticed the following in /var/log/gitlab/gitlab-rails/production.log
Started GET "/" for 127.0.0.1 at 2015-03-31 13:36:56 -0400
Processing by DashboardController#show as HTML
PG::Error: ERROR: relation "identities" does not exist
LINE 5: WHERE a.attrelid = '"identities"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"identities"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
Completed 500 Internal Server Error in 135ms
ActiveRecord::StatementInvalid (PG::Error: ERROR: relation "identities" does not exist
LINE 5: WHERE a.attrelid = '"identities"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"identities"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
):
app/models/user.rb:425:in `ldap_user?'
app/models/user.rb:463:in `requires_ldap_check?'
app/controllers/application_controller.rb:208:in `ldap_security_check'
I should note that we use LDAP authentication with Gitlab.
i am working on a project, in that project for every model we have two properties common
Created_ts
Created_by
I want to add a base class in which i want to set these properties, i tried using
class BaseModel < ActiveRecords::Base
end
class Person < BaseModel
end
when i create an instance of Person model it gives exception, i am not sure why it is giving exception, may be because it is looking for table BaseModels.
can any one please suggest, how to do this.
Exception :
PG::UndefinedTable: ERROR: relation "base_models" does not exist
LINE 5: WHERE a.attrelid = '"base_models"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"base_models"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "base_models" does not exist
LINE 5: WHERE a.attrelid = '"base_models"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"base_models"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
we just need to make the base class as abstract class
for more reference seek below link
Rails extending ActiveRecord::Base
Env: Rails 3.2.11
Added paper_trail gem.
Note that I already used that gem and I never had a problem but this time I am getting an error and I can't find out why.
In my Model:
class User < ActiveRecord::Base
has_paper_trail :versions => :paper_trail_versions
...
end
The error:
User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE ("users"."pseudo" = 'joel' AND "users"."id" != 21) LIMIT 1
PG::Error: ERROR: relation "versions" does not exist
LINE 5: WHERE a.attrelid = '"versions"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"versions"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
(0.1ms) ROLLBACK
Completed 500 Internal Server Error in 28ms
ActiveRecord::StatementInvalid (PG::Error: ERROR: relation "versions" does not exist
LINE 5: WHERE a.attrelid = '"versions"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"versions"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
)
any leads on how to troubleshoot this?
Have you followed the installation instructions:
Install PaperTrail as a gem via your Gemfile:
gem 'paper_trail', '~> 2'
Generate a migration which will add a versions table to your database.
bundle exec rails generate paper_trail:install
Run the migration.
bundle exec rake db:migrate
Add has_paper_trail to the models you want to track.
from https://github.com/airblade/paper_trail
I recently moved my Rails app to Postgres and noticed in the developments logs it's full of SQL statements like the following:
SQL (1.1ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"permissions"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
SQL (1.1ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"spaces"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
Anyone know what the deal is with this, seems like it's a performance hit? Is it?
Thanks
You can get rid of these messages with the silent-postgres gem.