Model.reset_column_information不会在rails迁移中重新加载列

我正在使用Rails 3.2并进行包含代码的迁移:

add_column :users, :gift_aid, :integer, :default => 2 # reset columns User.reset_column_information ... code here to load legacy data from sqlite3 database ... # now create a user with the loaded column data user = User.create( ...other cols..., :gift_aid => migrated_gift_aid_column_data, ...other cols... ) 

运行迁移时会得到unknown attribute: gift_aidUser.column_names在调用User.column_names之前和之后显示相同的列表。

奇怪的是,当我手动删除列在MySQL中,并重新运行迁移它按预期工作。 从第一次迁移开始,再次使用一个空的数据库,它不起作用,所以这是运行所有的迁移,而不是单一的迁移。

我有几个以前的用户模型的迁移,都包括reset_column_information和工作正常。

我真的在摸索这个问题 – 任何人都有任何想法

我认为这必定是某种与模式caching相关的错误…这可能工作:

 User.connection.schema_cache.clear! User.reset_column_information 

(对于Rails 3.2.2)