如何在Rails 5迁移中为MySQL创建UNSIGNED INT?

问题描述 投票:1回答:1

使用activerecord (< 5.0, >= 3.2),我能够使用activerecord-mysql-unsigned gem在我的MySQL数据库中创建一个UNSIGNED INT,但是没有对该gem的更新,我在Rails 5中找不到任何关于本机支持的文档。

是否有一个选项哈希或者可以在add_column方法中调用的东西允许这样做?

mysql ruby-on-rails ruby-on-rails-5
1个回答
2
投票

从Rails 5.1.x开始,有一个无符号整数,bigint,decimal和float in the schema adapter for MySQL的选项

迁移中的这类内容将适用于Rails 5.1.4

  def up
    create_table :unsigned_columns do |t|

      t.integer "positive", :unsigned => true

      t.timestamps
    end
  end
© www.soinside.com 2019 - 2024. All rights reserved.