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