2
我在tasks
表中有一個屬性,它的名字爲is_active
,它是boolean
。但是我忘了在創建表時將默認值設置爲這個屬性。所以現在我是試圖設置這個值默認爲true
,但正如我可以從sqlite瀏覽器看到的 - 新任務仍然創建與此值設置爲NULL
。請你幫我找到我的遷移問題在哪裏?MIgration沒有工作軌道
遷移文件:
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
顛倒遷移,添加hashrocket,仍然沒有變化 – Mikhah
嘗試取出'def change'塊,並且只留下'up'和'down'塊。看看是否有幫助 – Ren
是的,問題解決了,謝謝 – Mikhah