【问题标题】:unsigned int field in a Ruby on Rails migration?Ruby on Rails 迁移中的 unsigned int 字段?
【发布时间】:2010-11-11 16:38:22
【问题描述】:

我怎样才能使人口无符号?

  def self.up
    create_table :cities do |t|
      t.string :name
      t.integer :population
      t.float :latitude
      t.float :longitude

      t.timestamps
    end
  end

【问题讨论】:

  • 仅供参考,您现在应该能够将unsigned: true 传递到该行,这将使integer 无符号。

标签: sql ruby-on-rails ruby activerecord migration


【解决方案1】:

这应该适合你。

t.column :population, 'integer unsigned'

【讨论】:

    【解决方案2】:

    只是为了添加一件事。这完美地工作。但需要注意的是,它会使迁移代码数据库依赖。

    【讨论】:

      【解决方案3】:

      第 1 步:

      将 activerecord-mysql-unsigned 添加到 GemFile

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

      第 2 步: 安装宝石

      bundle install
      

      第三步:

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

      t.integer :cost, unsigned: true
      

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

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 2015-04-09
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多