Rails Rails 3, 如何支持 Pg 的 bigint 数据类型

michael_roshen · June 03, 2014 · Last by michael_roshen replied at June 03, 2014 · 2349 hits

需求: 项目中某个字段原来设置的数据类型是 integer, 后来业务变更,需要存储的 id 长度很长,integer 放不下,数据库用的是 pg,查了一下 pg 支持 bigint , 支持长度为:-9223372036854775808 到 9223372036854775807

测试: rails g scaffold user name:string age:bigint

执行 migrate 的时候:

StandardError: An error has occurred, this and all later migrations canceled:
undefined method `bigint' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0x000000041ac4e0>/home/chenc/gcj_project/gcj_project/test_bigint/db/migrate/20140603092600_create_users.rb:5:in `block in change'

咋搞的,重复提交表单 bug?发了两遍

t.column :name, 'bigint'

t.integer :age, limit: 8

#3 楼 @luikore limit 是控制长度的吗?有上限吗?

#3 楼 @luikore 8 字节 查到了,谢谢

You need to Sign in before reply, if you don't have an account, please Sign up first.