代码之家  ›  专栏  ›  技术社区  ›  tybro0103

Ruby on Rails迁移中的unsigned int字段?

  •  11
  • tybro0103  · 技术社区  · 14 年前

    我怎么能让人口没有签名?

      def self.up
        create_table :cities do |t|
          t.string :name
          t.integer :population
          t.float :latitude
          t.float :longitude
    
          t.timestamps
        end
      end
    
    3 回复  |  直到 14 年前
        1
  •  30
  •   rwilliams    14 年前

    这应该对你有用。

    t.column :population, 'integer unsigned'
    
        2
  •  7
  •   Indika K    14 年前

    只想再加一件事。这很管用。但需要注意的是,它将使迁移代码数据库依赖。

        3
  •  2
  •   Mohsen Alizadeh    11 年前

    步骤1:

    将未签名的activerecord mysql添加到GemFile

    # add unsigned integer support to mysql2 adapter
    gem "activerecord-mysql-unsigned", "~> 0.0.1"
    

    步骤2: 安装宝石

    bundle install
    

    步骤3:

    在您喜欢的字段中使用“unsigned:true”

    t.integer :cost, unsigned: true
    

    参考: http://rubydoc.info/gems/activerecord-mysql-unsigned/0.0.1/frames