问题
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.
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.
回答1:
For some reason the create table doesn't like bigint. You can, however do it with add_columm using the bigint data type:
add_column :table_name, :really_big_int, :bigint
Then you don't need that limit stuff.
回答2:
This works in Rails 4
t.column :really_big_int, :bigint
回答3:
Rails 5.0.0.1 it works:
def change
create_table :huge do |t|
t.integer :big_bastard, limit: 8
end
end
回答4:
In rails 4.2 + you can use like:
create_table :table_name do |t|
t.bigint :really_big_int
end
回答5:
I was able to create a bigint using t.column
. This is useful if you want to control the column order in the table.
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).
来源:https://stackoverflow.com/questions/7061239/rails-migration-bigint-on-postgresql-seems-to-be-failing