Rails 迁移:PostgreSQL 上的 Bigint 似乎失败了?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7061239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:12:49  来源:igfitidea点击:

Rails Migration: Bigint on PostgreSQL seems to be failing?

ruby-on-railspostgresqlactiverecordmigrationbigint

提问by Lonecat

Trying to create a table with a bigint column creates a standard integer column instead. What could be going wrong? I don't know where to start looking.

尝试创建一个带有 bigint 列的表会创建一个标准的整数列。可能出什么问题了?我不知道从哪里开始寻找。

I'm using this in the migration:

我在迁移中使用它:

create_table :table_name do |t|
  t.integer :really_big_int, limit: 8
end

I'm using Ruby 1.9.2, PostgreSQL 9.0.3 and Rails 3.0.9. I've dropped the database and ran the migrations several times and it still doesn't create the bigint column.

我使用的是 Ruby 1.9.2、PostgreSQL 9.0.3 和 Rails 3.0.9。我已经删除了数据库并多次运行迁移,但它仍然没有创建 bigint 列。

回答by Chris Barretto

For some reason the create table doesn't like bigint. You can, however do it with add_columm using the bigint data type:

出于某种原因,创建表不喜欢 bigint。但是,您可以使用 bigint 数据类型使用 add_columm 来执行此操作:

add_column :table_name, :really_big_int, :bigint

Then you don't need that limit stuff.

那么你不需要那个限制的东西。

回答by lstefani

This works in Rails 4

这适用于 Rails 4

t.column :really_big_int, :bigint

回答by rmcsharry

Rails 5.0.0.1 it works:

Rails 5.0.0.1 它的工作原理:

  def change
    create_table :huge do |t|  
      t.integer :big_bastard, limit: 8
    end
  end

回答by Thorin

In rails 4.2 + you can use like:

在 rails 4.2 + 中,您可以使用:

create_table :table_name do |t|
   t.bigint :really_big_int
end

回答by Mark Schneider

I was able to create a bigint using t.column. This is useful if you want to control the column order in the table.

我能够使用t.column. 如果您想控制表中的列顺序,这很有用。

create_table :table_name do |t|
  t.string :other_column
  t.column :really_big_int, :bigint
  .
  .
  t.timestamps
end

I'm using Rails 3.2.12 with pg gem version 0.15.1 (x86-mingw32).

我正在使用 Rails 3.2.12 和 pg gem 版本 0.15.1 (x86-mingw32)。