Search code examples
mysqlruby-on-railsruby-on-rails-5

How do I create an UNSIGNED INT for MySQL in a Rails 5 migration?


With activerecord (< 5.0, >= 3.2) I was able to use the activerecord-mysql-unsigned gem to create an UNSIGNED INT in my MySQL database, but there's been no updates to that gem and I can't find any documentation regarding native support for that in Rails 5.

Is there an options hash or something that can be called in the add_column method which allows this to be done?


Solution

  • There is an option for unsigned integer, bigint, decimal, and float in the schema adapter for MySQL as of Rails 5.1.x

    Something like this in your migration will work in Rails 5.1.4

      def up
        create_table :unsigned_columns do |t|
    
          t.integer "positive", :unsigned => true
    
          t.timestamps
        end
      end