ruby-Rails迁移:如何通过使用ROR迁移来增加列数据类型的大小

我的用户表登录列是String类型,限制为40个字符。现在,我计划将限制增加到55个字符。

请让我知道如何使用ROR迁移来增加此限制。

谢谢,Shravan

Sravan Kumar asked 2020-07-30T21:15:43Z
2个解决方案
58 votes
class YourMigration < ActiveRecord::Migration
  def up
    change_column :users, :login, :string, :limit => 55
  end

  def down
    change_column :users, :login, :string, :limit => 40
  end
end
beesasoh answered 2020-07-30T21:15:55Z
21 votes
class YourMigration < ActiveRecord::Migration
  def change
    change_column :users, :login, :string, :limit => 55
  end
end
tirdadc answered 2020-07-30T21:16:11Z
translate from https://stackoverflow.com:/questions/22351712/rails-migration-how-to-increase-column-data-type-size-by-using-ror-migration