Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :latitude
      t.float :longitude

      t.timestamps
    end
  end
like image 649
tybro0103 Avatar asked Nov 11 '10 16:11

tybro0103


2 Answers

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

like image 99
Mohsen Alizadeh Avatar answered Sep 20 '22 20:09

Mohsen Alizadeh


This should work for you.

t.column :population, 'integer unsigned'
like image 40
rwilliams Avatar answered Sep 21 '22 20:09

rwilliams