Here is my 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
I set the fo limit for the "name" column.
Then in the console:
user = User.new(name:"1234567890",email:" username@gmail.com ") user.save!
An error occurred:
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')
But when I switched to rails 3.
I found that it automatically shortened the string " 1234567890 " and inserted " 123456 " into the database without errors.
Has anything been removed about this in rails 4?
Should I add some truncation functions to the model myself? Thanks!
ruby-on-rails ruby-on-rails-4 rails-migrations
tzzzoz
source share