我需要使用外部提供的64位整数作为用户表的索引,这个整数可以被Rails存储,但如果它是主键就不行了。我有以下迁移代码:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users, :id => false do |t|
t.integer :id, limit: 8
t.string :name
t.timestamps null: false
end
end
end
迁移工作正常,没有报错,但是当我试图使用64位整数进行填充时,我收到以下提示:
RangeError: 76561198054432981 is out of range for ActiveRecord::Type::Integer with limit 4
显然,Rails忽略了limit字段,只要它是主键/:id字段?我该如何处理这个问题?
值得一提的是,我正在使用sqlite3(默认设置),但据我所知,sqlite完全能够存储64位整数。
这是来自sqlite的table_info:
0|id|integer(8)|0||0
1|name|varchar|0||0
2|created_at|datetime|1||0
3|updated_at|datetime|1||0