rails/rails — Issue #3279: [3.1.1] PGError: ERROR:  relation does not exist
Author: carhartl
Created: 2011-10-10 13:58:32+00:00
State: open

I am getting said 'PGError: ERROR: relation "abstract_items" does not exist' error with Rails 3.1.1 given a model that inherits from another class that is not abstract (setup actually extracted from an engine/gem I am using - [Omnipopulus](https://github.com/donfrancisco/omnipopulus)). With Rails 3.1.0 this was still fine.

Very simple setup as follows:

#models/item.rb
class Item < AbstractItem
end

#models/abstract_item.rb
class AbstractItem < ActiveRecord::Base
# no error when abstract...
# self.abstract_class = true
end

A simple query triggers the error for me, irb + trace:

irb(main):003:0> Item.count
PGError: ERROR: relation "abstract_items" does not exist
LINE 4: WHERE a.attrelid = '"abstract_items"'::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 = '"abstract_items"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

ActiveRecord::StatementInvalid: PGError: ERROR: relation "abstract_items" does not exist
LINE 4: WHERE a.attrelid = '"abstract_items"'::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 = '"abstract_items"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1003:in `async_exec'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1003:in `exec_no_cache'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:591:in `block in exec_query'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:590:in `exec_query'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1102:in `column_definitions'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:781:in `columns'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `block (2 levels) in initialize'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:92:in `block in initialize'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `yield'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `default'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `block in initialize'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:717:in `yield'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:717:in `default'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:717:in `columns_hash'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:827:in `descends_from_active_record?'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:833:in `finder_needs_type_condition?'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:978:in `relation'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/named_scope.rb:36:in `scoped'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:445:in `count'
from (irb):3
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /Users/carhartl/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'