【发布时间】:2012-01-27 11:15:03
【问题描述】:
我在这里看到了一些关于向现有列添加默认布尔值的问题(即this one)。所以我尝试了change_column 的建议,但我一定做得不对。
我试过了:
$ change_column :profiles, :show_attribute, :boolean, :default => true
返回-bash: change_column: command not found
然后我跑了:
$ rails g change_column :profiles, :show_attribute, :boolean, :default => true
...和
$ rails change_column :profiles, :show_attribute, :boolean, :default => true
然后运行rake db:migrate,但:show_attribute 的值仍然是nil。在我上面提到的问题中,它在 PostgreSQL 中说您需要手动更新它。由于我使用的是 PostgreSQL,因此我在 create_profiles 迁移中添加了以下内容:
t.boolean :show_attribute, :default => true
谁能告诉我我在这里做错了什么?
【问题讨论】: