gpt4 book ai didi

mysql - 更新后的 ID 列仍然失败,并出现 RangeError

转载 作者:行者123 更新时间:2023-11-29 21:00:21 24 4
gpt4 key购买 nike

我的应用程序中有一个自动递增的 ID 字段,它已达到 mysql 中中等 int 的上限 2147483647。我收到以下错误:

范围错误:2147483656 超​​出 ActiveRecord::Type::Integer 的范围,限制为 4

我创建了一个迁移以使 ID 成为 bigint:

change_column :my_model_names, :id, :integer, limit: 8, auto_increment: true

这似乎有效 - 这是 mysql 命令行中对该字段的描述:

+-----------------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------------+---------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
+-----------------------------+---------------+------+-----+---------+----------------+

在 Rails 控制台中,当我查询 MyModelName.columns 时,我可以看到该列看起来是正确的:

2.2.2 :045 > MyModelName.columns[0]
> #<ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column:0x007f98bf6d6640 @strict=true, @collation=nil, @extra="auto_increment", @name="id", @cast_type=#<ActiveRecord::Type::Integer:0x007f98bf6e7490 @precision=nil, @scale=nil, @limit=8, @range=-9223372036854775808...9223372036854775808>, @sql_type="bigint(20)", @null=false, @default=nil, @default_function=nil>

它的 limit=8 并且范围远远超出了我试图保存的值,但我仍然遇到相同的错误:

2.2.2 :045 > MyModelName.new.save
RangeError: 2147483657 is out of range for ActiveRecord::Type::Integer with limit 4

有趣的是,即使未保存记录,自动增量值也会更新。如果我再试一次,ID 值就会增加:

RangeError: 2147483658 is out of range for ActiveRecord::Type::Integer with limit 4

版本信息

activerecord (4.2.5.1)
mysql2 (0.3.18)

最佳答案

是否有任何 update/after_save 回调将此值传播到也需要调整大小的类似外键?

关于mysql - 更新后的 ID 列仍然失败,并出现 RangeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37286197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com