Rails 4 "undefined" accessor "method after migration

My Rails 4.1.5 app is on Ruby 2.1 and uses postgresql with hstore for store_accessor. Starting with a new database:

rake db:migrate; rake db:seed

      

... everything works fine.

Rollback and fast forward and here's where the problem starts:

rake db:migrate VERSION=0; rake db:migrate; rake db:seed

      

The model reports "undefined accessor method" if I try to access any of the "it" properties.

undefined method `accessor' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Identity:0xyaddayadda>

      

The model uses store_accessor with postrgesql hstore. The model is defined as follows:

class Foo < ActiveRecord::Base
  ...
  store_accessor :properties, :color, :material, :brand
  ...
end

      

And migration is defined as follows:

class CreateFoos < ActiveRecord::Migration
  def change
    enable_extension "hstore"
    create_table :foos do |t|
      t.hstore      :properties

      t.timestamps
    end
  end
end

      

To fix the problem, I can completely destroy the db before I recreate it:

rake db:migrate VERSION=0; rake db:drop:all; rake db:create; rake db:migrate; rake db:seed

      

This means the test environment and dev stop and restart every time, which is a problem.

I tried to add another migration that enables / disables hstore:

class AddHstore < ActiveRecord::Migration
  def up
    enable_extension :hstore
  end
  def down
    disable_extension :hstore
  end
end

      

This is done before migrating Foo.

I suspect this is a posgresql ActiveRecord connector issue. I may be using this incorrectly, which is why I want to bounce off you guys.

+3
activerecord postgresql ruby-on-rails-4 hstore


source to share


No one has answered this question yet

Check out similar questions:

659
Error on getting: Peer authentication failed for user "postgres" when trying to get pgsql to work with rails
596
How to use problems in Rails 4
310
Rails 4: list of available datatypes
293
Add reference column migration in Rails 4
4
Cast JSON Column Type to HSTORE Column Type
0
ActiveRecord has_one relationships do not return in some cases
0
Rails activerecord - cannot access columns
0
rails from many to many relationships from the start (all simulation)
0
Can't display only user nested objects
0
"rake db: migrate" doesn't work correctly. Don't create tables in my simple_cms in my model



All Articles
Loading...
X
Show
Funny
Dev
Pics