Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 为什么Rails在创建新记录时在SQL查询中生成二进制文件_Mysql_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Mysql 为什么Rails在创建新记录时在SQL查询中生成二进制文件

Mysql 为什么Rails在创建新记录时在SQL查询中生成二进制文件,mysql,ruby-on-rails,ruby-on-rails-3,Mysql,Ruby On Rails,Ruby On Rails 3,我有模型项目和位置 这是我的项目模型迁移文件: class CreateItems < ActiveRecord::Migration def change create_table :items do |t| t.string :item_cd t.string :item_name t.integer :location_id t.timestamps end end end 为什么SQL在项目行中有BINAR

我有模型项目和位置

这是我的项目模型迁移文件:

class CreateItems < ActiveRecord::Migration
  def change
    create_table :items do |t|
      t.string :item_cd
      t.string :item_name

      t.integer :location_id
      t.timestamps
    end
  end
end
为什么SQL在项目行中有
BINARY
?我插入一个字符串以在表单上创建项目\ U cd。谁能告诉我什么是问题吗


我正在使用mysql数据库。

看起来您的模型中有一些验证,如

validates :item_cd, :uniqueness => true
显然,这将使模型检查数据库中是否存在相等的值,从而执行
Exist
查询

字符串“6”在比较之前转换为二进制的原因是
char
varchar
值的二进制比较更快。通常情况下,比较会经过排序过程,以便(例如,'6'='6'或'a'='a'。由于查询只需要检索精确匹配(也不是值,只是它们的存在:SELECT 1),所以二进制比较就足够了

您还可以查看相关的MySQL文档:

validates :item_cd, :uniqueness => true