奇怪的Heroku浮点位精度错误(轨道上的红宝石) [英] Strange Heroku float bit-precision error (ruby on rails)

查看:231
本文介绍了奇怪的Heroku浮点位精度错误(轨道上的红宝石)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原来我的模型上的坐标字段是使用整数,但是当我试图部署到Heroku时,我被提醒(崩溃),我需要它是一个浮点数(因为我有我的坐标小数点) 。所以我在我的本地机器上生成了一个change_column迁移,改为将它们变为floats。并且一切正常。

我试着再次部署到heroku,首先使用 heroku pg:reset ,然后用 heroku db:setup 。在db:setup期间,出现以下错误:
$ b $ p

PGError:错误:float类型的精度必须小于54位
:CREATE TABLE地标(id串行主键,名称字符变化(255),xcoord浮动(255),ycoord浮动(255),created_at时间戳,updated_at时间戳)所以我产生了另一个change_column迁移,这次也是:precision选项(设置为:precision => ; 50 ,小于54)。我再次完成了整个部署过程,它给了我同样的错误。



我做错了什么?我已经部署了另一个应用程序Heroku之前,使用浮动没有任何修改...

我在本地机器上使用SQLite,我认为Heroku使用Postgres?

感谢提前!

编辑:我也应该提一下,输出SQL后显示错误改变了我的坐标的:precision 值仍然说'float(255)'...不知道为什么]

解决方案

不要使用float(255)作为列类型。使用 real 双精度。请阅读 http://www.postgresql.org/docs /8.3/static/datatype-numeric.html#DATATYPE-FLOAT



另外,强烈推荐使用postgres在本地进行开发。在开发和生产之间大量切换堆栈的重要组成部分时,遇到不一致性(例如这种情况)是很常见的。而你的数据库是你的堆栈的重要组成部分。


Originally a coordinate field on my model was using integer, but when I tried to deploy to Heroku, I was reminded (by a crash) that I needed it to be a float instead (since I had decimal points in my coordinate). So I generated a change_column migration on my local machine, to change_column them to be floats instead. and everything went fine.

I tried to deploy to heroku again, first with a heroku pg:reset and then with a heroku db:setup. During the db:setup, I get the following error:

PGError: ERROR: precision for type float must be less than 54 bits : CREATE TABLE "landmarks" ("id" serial primary key, "name" character varying(255), "xcoord" float(255), "ycoord" float(255), "created_at" timestamp, "updated_at" timestamp)

So I generated another change_column migration, this time with :precision option as well (set to :precision => 50, which is less than 54). I went through the whole deploy process again, and it gave me the same error.

Am I doing something wrong? I've deployed another app to Heroku before that used float without any modification...

I'm using SQLite on my local machine, and I think Heroku uses Postgres?

Thanks in advance!

[EDIT: I should also mention that the output SQL the error displayed after I changed the :precision value for my coords still said 'float(255)'...not sure why]

解决方案

Don't use float(255) as the column type. Use either real or double precision. Please read http://www.postgresql.org/docs/8.3/static/datatype-numeric.html#DATATYPE-FLOAT

Also we strongly recommend using postgres locally for development. It is all too common to run into inconsistencies—such as this—when drastically switching important parts of your stack between development and production. And your database is an important part of your stack.

这篇关于奇怪的Heroku浮点位精度错误(轨道上的红宝石)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆