Rails не работает bigint?

Rails 5.2.3
старая миграция:
class CreateTmpUsers < ActiveRecord::Migration[5.2]
	def change
		create_table(:tmp_users) do |t|
			t.integer :external_id
			...
		end
		add_index ...
	end
end

последняя миграция:
class MigrateToRails52 < ActiveRecord::Migration[5.2]
	def up
		change_column :tmp_users, :external_id, :bigint
...
end


schema.db после миграций:
create_table "tmp_users", force: :cascade do |t|
    t.bigint "external_id"
...
  end


schema.db после rails db:schema:dump
create_table "tmp_users", force: :cascade do |t|
    t.bigint "external_id"
...
  end


в pgadmin смотрю:
Тип данных: bigint

TmpUsers.inspect дает
TmpUser(id: integer, external_id: integer, name: strin...

Запись в базу через ActiveRecord дает:
message: 392169714724389808 is out of range for ActiveModel::Type::Integer with limit 4 bytes
error class: ActiveModel::RangeError


Ну почему рельса не соображает, что 8 байт, а не 4
  • Вопрос задан
  • 419 просмотров
Пригласить эксперта
Ответы на вопрос 1
inf
@inf
DevOps Engineer
https://stackoverflow.com/a/3736425/1697148

Here's the magic incantation in your migration when you declare the column:
create_table :example do |t|
  t.integer :field, :limit => 8
end


Вроде в 6ой рельсе пофиксили.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы