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


source to share





All Articles