Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

self.table_name problems with 'find_or_create_by_' #4882

Closed
ened opened this Issue · 15 comments

6 participants

@ened

Given my model looks like this:

class APN::Device < APN::Base
  self.table_name = 'apn_devices'

  has_many :notifications, :class_name => 'APN::Notification'

With 1 column token:string. Its base class looks like this:

module APN
  class Base < ActiveRecord::Base # :nodoc:

    # def self.table_name # :nodoc:
    #    self.to_s.gsub("::", "_").tableize
    # end

  end
end

I already tried commenting in/out the self.table_name method and the self.table_name = calls in the child classes.

Then I can use this method to find a Device by token:

ruby-1.9.2-p290 :004 > APN::Device.find_by_token('xxxx xxxx xxxx xxxx')
  APN::Device Load (0.5ms)  SELECT "apn_devices".* FROM "apn_devices" WHERE "apn_devices"."token" = 'xxxx xxxx xxxx xxxx' LIMIT 1
 => nil 

But once I try to use find_or_create_by_token:

ruby-1.9.2-p290 :005 > APN::Device.find_or_create_by_token('xxxx xxxx xxxx xxxx')
  APN::Device Load (0.5ms)  SELECT "apn_devices".* FROM "apn_devices" WHERE "apn_devices"."token" = 'xxxx xxxx xxxx xxxx' LIMIT 1
ActiveRecord::StatementInvalid: PGError: ERROR:  relation "bases" does not exist
LINE 4:              WHERE a.attrelid = '"bases"'::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 = '"bases"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `async_exec'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `exec_no_cache'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in exec_query'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `exec_query'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1231:in `column_definitions'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:845:in `columns'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `yield'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `default'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `columns'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:248:in `column_names'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:44:in `block in define_attribute_methods'
    from <internal:prelude>:10:in `synchronize'
... 3 levels...
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:41:in `define_attribute_methods'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:145:in `respond_to?'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:81:in `block in assign_attributes'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:78:in `each'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/relation/finder_methods.rb:290:in `block in find_or_instantiator_by_attributes'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/base.rb:497:in `initialize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/relation/finder_methods.rb:289:in `new'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/relation/finder_methods.rb:289:in `find_or_instantiator_by_attributes'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/dynamic_matchers.rb:47:in `method_missing'
    from (irb):5
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

All of this is happening with Rails3.2 and Ruby1.9.2. bundle list:
Gems included by the bundle:

  * RedCloth (4.2.9)
  * ZenTest (4.5.0)
  * actionmailer (3.2.1)
  * actionpack (3.2.1)
  * activemodel (3.2.1)
  * activerecord (3.2.1)
  * activeresource (3.2.1)
  * activesupport (3.2.1)
  * apn_on_rails (0.3.1rails3 fdbe81b)
  * arel (3.0.0)
  * autotest (4.4.6)
  * autotest-growl (0.2.16)
  * autotest-rails (4.1.1)
  * bcrypt-ruby (3.0.1)
  * builder (3.0.0)
  * bundler (1.0.21)
  * cancan (1.6.7)
  * capistrano (2.9.0)
  * carrierwave (0.5.8)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.2.0)
  * configatron (2.9.0)
  * devise (2.0.0)
  * diff-lcs (1.1.3)
  * erubis (2.7.0)
  * exception_notification_rails3 (1.2.0)
  * execjs (1.3.0)
  * ffi (1.0.11)
  * guard (1.0.0)
  * guard-rspec (0.6.0)
  * haml (3.1.4)
  * haml-rails (0.3.4)
  * highline (1.6.11)
  * hike (1.2.1)
  * i18n (0.6.0)
  * irwi (0.4.1 b78694c)
  * journey (1.0.1)
  * jquery-rails (2.0.0)
  * json (1.6.5)
  * libv8 (3.3.10.4)
  * machinist (2.0)
  * mail (2.4.1)
  * metaclass (0.0.1)
  * mime-types (1.17.2)
  * mini_magick (3.4)
  * mocha (0.10.3)
  * multi_json (1.0.4)
  * net-scp (1.0.4)
  * net-sftp (2.0.5)
  * net-ssh (2.3.0)
  * net-ssh-gateway (1.1.0)
  * nifty-generators (0.4.6)
  * orm_adapter (0.0.6)
  * pg (0.12.2)
  * polyamorous (0.5.0)
  * polyglot (0.3.3)
  * rack (1.4.1)
  * rack-cache (1.1)
  * rack-ssl (1.3.2)
  * rack-test (0.6.1)
  * rails (3.2.1)
  * rails_autolink (1.0.5)
  * railties (3.2.1)
  * rake (0.9.2.2)
  * ransack (0.6.0)
  * rdoc (3.12)
  * rspec (2.8.0)
  * rspec-core (2.8.0)
  * rspec-expectations (2.8.0)
  * rspec-mocks (2.8.0)
  * rspec-rails (2.8.1)
  * rubyzip (0.9.5)
  * sass (3.1.12)
  * sass-rails (3.2.4)
  * simplecov (0.5.4)
  * simplecov-html (0.5.3)
  * sprockets (2.1.2)
  * sqlite3 (1.3.5)
  * sqlite3-ruby (1.3.3)
  * subexec (0.2.1)
  * therubyracer (0.9.9)
  * thor (0.14.6)
  * tilt (1.3.3)
  * treetop (1.4.10)
  * tzinfo (0.3.31)
  * uglifier (1.2.3)
  * warden (1.1.0)
  * yamler (0.1.0)

I didn't test it further, in order to pinpoint it to the postgresql adapter. It seems to me more like a find_or_create_by_ issue?

@ened

Addition:

Same thing happens with calls to '.new':

ruby-1.9.2-p290 :007 > APN::Device.new(:token => '123')
ActiveRecord::StatementInvalid: PGError: ERROR:  relation "bases" does not exist
LINE 4:              WHERE a.attrelid = '"apn_bases"'::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 = '"apn_bases"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `async_exec'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `exec_no_cache'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in exec_query'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `exec_query'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1231:in `column_definitions'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:845:in `columns'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `yield'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `default'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `columns'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:248:in `column_names'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:44:in `block in define_attribute_methods'
    from <internal:prelude>:10:in `synchronize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:41:in `define_attribute_methods'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:43:in `block in define_attribute_methods'
    from <internal:prelude>:10:in `synchronize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:41:in `define_attribute_methods'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:145:in `respond_to?'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:81:in `block in assign_attributes'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:78:in `each'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/base.rb:495:in `initialize'
    from (irb):7:in `new'
    from (irb):7
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
@ened

Perhaps helpful:

ruby-1.9.2-p290 :002 > APN::Device.table_name
 => "apn_devices" 
ruby-1.9.2-p290 :003 > APN::Device.new
ActiveRecord::StatementInvalid: PGError: ERROR:  relation "bases" does not exist
LINE 4:              WHERE a.attrelid = '"bases"'::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 = '"bases"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `async_exec'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `exec_no_cache'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in exec_query'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `exec_query'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1231:in `column_definitions'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:845:in `columns'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `yield'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `default'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:228:in `columns'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/model_schema.rb:248:in `column_names'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:44:in `block in define_attribute_methods'
    from <internal:prelude>:10:in `synchronize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:41:in `define_attribute_methods'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:43:in `block in define_attribute_methods'
    from <internal:prelude>:10:in `synchronize'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:41:in `define_attribute_methods'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:145:in `respond_to?'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:398:in `__run_callback'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_initialize_callbacks'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/base.rb:498:in `initialize'
    from (irb):3:in `new'
    from (irb):3
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
    from /Users/ened/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'ruby-1.9.2-p290 :004 >
@ened

More information after testing. The error disappears if I remove the Base class and set the table name via self.table_name in the child classes.
As soon I even add a empty base class in between the model and ActiveRecord::Base, it will break again.

@ened

Fixed once I put

self.abstract_class = true

in the base class.

@ened ened closed this
@yanivmatbit

Ened, you are a life saver!

@williscool

what if you already have self.abstract_class = true in the base class :(

@ened
@williscool

Let me know if you need anything else but

ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

* activerecord (2.3.11)
* rails (2.3.11)

and the stack trace

SQL (0.0ms)  PGError: ERROR: relation "bases" does not exist
LINE 4: WHERE a.attrelid = '"bases"'::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 = '"bases"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum
Exception: ActiveRecord::StatementInvalid: PGError: ERROR:  relation "bases" does not exist
LINE 4:              WHERE a.attrelid = '"bases"'::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 = '"bases"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
: /Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `rescue in log'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/connection_adapters/abstract_adapter.rb:204:in `log'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/newrelic_rpm-3.3.1/lib/new_relic/agent/instrumentation/active_record.rb:31:in `block in log_with_newrelic_instrumentation'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/newrelic_rpm-3.3.1/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/newrelic_rpm-3.3.1/lib/new_relic/agent/instrumentation/active_record.rb:28:in `log_with_newrelic_instrumentation'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:507:in `query'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1063:in `column_definitions'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:675:in `columns'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/base.rb:1305:in `columns'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/base.rb:3067:in `attributes_from_column_definition'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/locking/optimistic.rb:66:in `attributes_from_column_definition_with_lock'
/Users/williamh/.rvm/gems/ruby-1.9.3-p0@app/gems/activerecord-2.3.11/lib/active_record/base.rb:2473:in `initialize'
@ened ened reopened this
@frodsan

@ened is this still an issue?

@ened

I did not run into this issue again.

However @williscool might have further testing done.

@williscool

So I still run into it every now and then.

The solution I've found has been to set the environment for rails explicitly so for example if you use thin

instead of

bundle exec thin start

I do

bundle exec thin -e development start

and it works fine.

Why? I have no idea.

@carlosantoniodasilva

@williscool we'd need more examples about your models structure that are raising this error to try some help. Anyway, I see you're using 2.3, which is not "supported" anymore (it won't get new releases), unless you want to try out a pull request to fix the problem by your own and start using from 2-3-stable branch.

I'm closing this since the original one is ok. Thanks!

@williscool

Yeah its no problem we're in the process of updating to Rails 3 now so it shouldn't be an issue anymore and that command from before consistently gets it to work until then.

Thanks for your help

@carlosantoniodasilva

@williscool great, let us know if you find any related problem on latest 3 versions.

@arrows

I'm on rails 3.2.3 and I have the same problem. I'm on the rails3 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.