Heroku pg,不能以限制 19 迁移 int

Heroku pg, can not migrate int with limit 19

我有一个数据库列作为 integet 设置为限制 19。它在本地主机上工作正常,因为我有 sqlite。但是我无法在 Heroku pg 数据库上迁移。

class AdddivIdToLocations < ActiveRecord::Migration
  def change
    add_column :locations, :div_id, :integer, :limit => 19
  end
end

然后我尝试将列从整数更改为字符串,这样会更好。但是因为它无法进行 heroku run rake db:migrate 我无法更改列类型。我该怎么办?

class AdddivIdToLocationsTypeChange < ActiveRecord::Migration

  def self.up
    change_table :locations do |t|
      t.change :div_id, :string
    end
  end
  def self.down
    change_table :locations do |t|
      t.change :div_id, :integer
    end
  end
end

div_id的最大值是多少?

:limit 指定最大存储大小(以字节为单位)- 可用值如下:

+------------------------------------------------------------+
| :limit | Numeric Type  | Column Size |      Max Value      |
|--------+---------------+-------------+---------------------|
|    1   |    TINYINT    |   1 byte    | 127                 |
|    2   |    SMALLINT   |   2 bytes   | 32767               |
|    3   |    MEDIUMINT  |   3 bytes   | 8388607             |
|    4   |     INT(11)   |   4 bytes   | 2147483647          |
|    8   |     BIGINT    |   8 bytes   | 9223372036854775807 |
+------------------------------------------------------------+

如果您未指定任何值,则默认值为 4 INT(11)。如果您的值大于整数,则设置 limit: 8 以便它可以存储 BIGINT。 19 不是有效值。

您可以更新 limit: 部分迁移和 运行 再次更新 db:migrate。 如果要更改列类型,则首先必须存在此列,因为 运行 db:migrate 没有 limit: