我在tasks表中有一个属性,名为is_active,它名为boolean.But --我在创建table.So时忘记将默认值设置为table.So--现在我试图默认将这个值设置为true,但正如我从sqlite中看到的--新任务仍然在创建中,这个值设置为NULL.Can --请帮助我找出迁移中的问题所在?
迁移文件:
class AddDefaultValueToTask < ActiveRecord::Migration[5.0]
def change
def up
change_column :tasks, :is_active, :boolean, :default => true
end
def down
change_column :tasks, :is_active, :boolean, :default => nil
end
end
endSchema.rb文件
create_table "tasks", force: :cascade do |t|
t.text "body"
t.boolean "is_active"
t.integer "project_id"
t.string "deadline"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["project_id"], name: "index_tasks_on_project_id"
end发布于 2016-08-11 18:48:04
您缺少了哈希火箭操作符:“=>”
change_column :tasks, :is_active, :boolean, :default => true另外,如果您使用的是up和down,那么您需要删除change块。这两种方法不能同时使用。
https://stackoverflow.com/questions/38903836
复制相似问题