这是我的schema.rb
create_table "users", force: true do |t|
t.string "name", limit: 6
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
end
我为“name”列设置了字符串限制.
然后,在控制台中:
user = User.new(name:"1234567890",email:"username@gmail.com")
user.save!
它引发了错误:
ActiveRecord::StatementInvalid: Mysql2::Error: Data too long for column 'name' at row 1: INSERT INTO `users` (`created_at`, `email`, `name`, `updated_at`) VALUES ('2014-06-19 15:08:15', 'username@gmail.com', '1234567890', '2014-06-19 15:08:15')
但是,当我切换到rails 3时.
我发现它自动截断了字符串“1234567890”,并将“123456”插入数据库而没有错误.
在轨道4中有什么关于这个被删除了吗?
我应该自己在模型中添加一些截断函数吗?谢谢!