0
我正在使用Rails4與MySQL。我已經生成了一些遷移,並提到了某些字段的默認值,但在創建行後,缺省值在數據庫中存儲爲「NULL」。Rails4遷移默認值不存儲到數據庫中
class CreateCities < ActiveRecord::Migration
def change
create_table :cities do |t|
t.string :name
t.integer :region_id
t.integer :country_id
t.integer :status, :default => 0
t.timestamps
end
end
end
我不明白爲什麼它不存儲!在控制器部分也做了這樣的,
def city_params
params.require(:city).permit!
end
那麼,什麼是它存儲狀態的值?空值?當你向服務器發出請求時,你可以發佈你在終端上看到的Rails服務器中的參數嗎? – Surya 2014-11-08 06:24:32
您嘗試添加null:false – argentum47 2014-11-08 08:57:27