I migrated from Rails 3.1.3 to 3.2.1 and got the following error when loading the home page:
PGError: ERROR: relation "translations" does not exist
LINE 4: WHERE a.attrelid = '"translations"'::regclass
^
: 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 = '"translations"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
This happens when globalize3 gem tries to build the relation between page_meta_tags and page_meta_tag_translations tables. Everything worked fine on Rails 3.1.3. Can it be due to new Active Record and globalize3 incompatibility? Anyone has the same thing?
class PageMetaTag < ActiveRecord::Base
translates :title, :description, :keywords
accepts_nested_attributes_for :translations
end
try using globalize3 beta:
gem 'globalize3', '0.2.0.beta8'
Related
I have been in trouble with this error caused when I started to code my tests on ruby on rails.
I have search in the web but the posts that I have found did not help me. I leave the references:
Rails: Relation does not exist for reference with class name in production
https://github.com/rails/rails/issues/29206
PG undefinedtable error relation users does not exist
This is the test that I made:
App/test/models/material_test.rb
require 'test_helper'
class MaterialTest < ActiveSupport::TestCase
test "the truth" do
assert true
end
end
When I try to execute it using:
rails test
I got the following error:
# Running:
E
Error:
CategoriesControllerTest#test_the_truth:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "object_formats" does not exist
LINE 8: WHERE a.attrelid = '"object_formats"'::regcla...
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
c.collname, col_description(a.attrelid, a.attnum) AS comment
FROM pg_attribute a
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
LEFT JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
WHERE a.attrelid = '"object_formats"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
My repo is public and the code is up to date.
https://github.com/FragmentX/FRAGMENTX
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'm trying to use the Ruby gem Fuzzily in my rails application, but am getting this error
relation "trigrams" does not exist
I followed all the instructions from https://github.com/mezis/fuzzily
Here's my code
trigram.rb
class Trigram < ActiveRecord::Base
include Url::Model
include Fuzzily::Model
end
url.rb
class Url < ActiveRecord::Base
fuzzily_searchable :short_url
end
add_trigram_mode.rb
class AddTrigramsModel < ActiveRecord::Migration
extend Url::Migration
extend Fuzzily::Migration
trigrams_owner_id_column_type = :uuid
end
I did a rake db:migrate. When I execute this in rails console, I get:
Url.find_by_fuzzy_short_url('sojdgl')
Url Load (1.4ms) SELECT "urls".* FROM "urls" ORDER BY "urls"."id" ASC LIMIT 100
PG::UndefinedTable: ERROR: relation "trigrams" does not exist
LINE 5: WHERE a.attrelid = '"trigrams"'::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 = '"trigrams"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "trigrams" does not exist
LINE 5: WHERE a.attrelid = '"trigrams"'::regclass
I named the migration file incorrectly. I works when I changed it to 20150830110623_add_trigrams_model.rb
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 am running a Rails 3.0.3 with Postgres 9.0.1 and delayed_job 2.1.1. I configured delayed_job for Solr reindexing on an after_save callback which works great in development. When running cucumber tests for the model in question's create method, I get:
(::) failed steps (::)
PGError: ERROR: relation "delayed_jobs" does not exist
LINE 4: WHERE a.attrelid = '"delayed_jobs"'::regclass
^
: 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 = '"delayed_jobs"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
(ActiveRecord::StatementInvalid)
./app/controllers/admin/items_controller.rb:11:in create'
./features/step_definitions/web_steps.rb:29
./features/step_definitions/web_steps.rb:14:inwith_scope'
./features/step_definitions/web_steps.rb:28:in /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/'
features/admin/item_create.feature:20:inAnd I press "Create"'
Any ideas?
Thanks
i.e. you should run rake db:test:clone
Probably you haven't run migrations on the test database.
please use
rake db:migrate:up VERSION=20080906120000 RAILS_ENV=test