【发布时间】:2017-01-28 15:22:00
【问题描述】:
我在一个项目中使用 Rails 和 SQL Server。当我在模型中进行以下验证时:validates :Clave, uniqueness: true 我收到此错误:can't cast ActiveRecord::ConnectionAdapters::SQLServer::Type::Char::Data to varchar
这是我的 schema.rb
create_table "Productos", primary_key: "Clave", force: :cascade do |t|
t.integer "Id", limit: 4, null: false
t.varchar "Producto", limit: 255
t.varchar "CodBarras", limit: 50
t.varchar "IdEmpresa", limit: 50
end
这是我的模型 producto.rb
class Producto < ActiveRecord::Base
self.primary_key = "Clave"
validates :IdEmpresa, uniqueness: true
validates :Clave, uniqueness: true
validates :Producto, presence: true
end
【问题讨论】:
-
ActiveRecord::ConnectionAdapters::SQLServer::Type::Char::Data to varchar看起来像列类型错误 -
@HarlemSquirrel 仅发生在字符串中,其他字段为整数不会发生
标签: ruby-on-rails sql-server validation ruby-on-rails-4 tiny-tds