开发者

unsigned int field in a Ruby on Rails migration?

How could I make population unsigned?

  def self.up
    create_table :cities do |t|
      t.string :name
      t.integer :population
      t.float :latit开发者_如何学JAVAude
      t.float :longitude

      t.timestamps
    end
  end


This should work for you.

t.column :population, 'integer unsigned'


Just to add one more thing. This works perfectly. But need to note that it will make the migration code database dependent.


step 1:

add activerecord-mysql-unsigned to GemFile

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

step 2: install gems

bundle install

step 3:

use "unsigned: true" in fields you like

t.integer :cost, unsigned: true

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜