gpt4 book ai didi

ruby-on-rails - 从 Rails 将 float 保存到 PostgreSQL 时出错

转载 作者:行者123 更新时间:2023-11-29 13:35:15 27 4
gpt4 key购买 nike

我最近刚切换到 PostgreSQL.. 只是想知道这个问题:

PG::Error: ERROR:  column "bathrooms" is of type double precision but expression is of type    character varying at character 161
HINT: You will need to rewrite or cast the expression.
: INSERT INTO "properties" ("address", "bathrooms", "bedrooms", "city", "country", "created_at", "description", "name", "state", "updated_at", "zip") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id"

迁移看起来像这样:

class CreateProperties < ActiveRecord::Migration
def change
create_table :properties do |t|
t.string :name
t.string :address
t.string :city
t.string :state
t.string :zip
t.string :country
t.float :bedrooms
t.float :bathrooms
t.string :country
t.text :description

t.timestamps
end
end
end

最佳答案

我将 float 切换为 decimal,PostgreSQL 现在似乎可以使用隐式转换了?

无论哪种方式,错误都消失了,谢谢

关于ruby-on-rails - 从 Rails 将 float 保存到 PostgreSQL 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14343368/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com