ruby-on-rails - Rails 将值保存到数据库超出限制
问题描述
我在 Rails 6 中有这个模式
create_table "fields", force: :cascade do |t|
t.string "title", limit: 100
t.text "description"
t.string "slug", limit: 20
t.integer "requests"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["slug"], name: "index_fields_on_slug", unique: true
t.index ["title"], name: "index_fields_on_title", unique: true
在rails控制台内部:
field = Field.new
field.slug = 'a' *25
field.save
并且该条目已成功保存在字段表中。为什么?我的 :slug 限制为 20。如果没有在模型中验证,那不应该失败吗?
解决方案
推荐阅读
- tensorflow - conda env 和 jupyter notebook 中的 Tensorflow 版本不同
- linux - 能够在 bash SED 中使用变量
- ios - CordovaError:承诺被非错误拒绝:错误代码 65
- java - 如何访问类(实现可运行)字段
- sql - SQL 窗口函数
- c - 如何使用scanf从用户那里获取没有空格的字符串?
- python - 莳萝能记住一个类使用的库吗?
- facebook - Facebook API 保存的位置
- python - 抓取链接和标题 - 用 beautifulsoup 存储在字典中
- java - 当用户输入任何不是双精度的内容时如何打印错误消息?