【发布时间】:2016-12-18 15:12:51
【问题描述】:
我在tasks 表中有一个属性,它被命名为is_active,它是boolean。但是我在创建表时忘记为这个属性设置默认值。所以现在我尝试将此值默认设置为true,但正如我从sqlite浏览器中看到的那样 - 新任务仍在创建,此值设置为NULL。您能帮我找出迁移中的问题吗?
迁移文件:
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
end
Schema.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
【问题讨论】:
标签: sql ruby-on-rails sqlite