“未知OID"的来源是什么? Rails中的错误? [英] What is the source of "unknown OID" errors in Rails?

查看:114
本文介绍了“未知OID"的来源是什么? Rails中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将应用程序复制到生产环境时,我的POSTGIS表列开始出现异常,Rails通知我有一个未知的OID 26865",并且这些字段将被视为String.

When replicating an app to production, my POSTGIS table columns started misbehaving, with Rails informing me there was an "unknown OID 26865" and that the fields would be treated as String.

而不是current_pos产生e. G. #<RGeo::Geographic::SphericalPointImpl:0x22fabdc "POINT (13.39318248760133 52.52908798020595)">我会得到0101000020E6100000FFDD958664C92A403619DEE6B2434A40.看起来好像没有安装activerecord-postgis-adapter或安装不当,但是我通过测试数据类型RGeo :: Feature :: Point的存在以及通过测试分配来消除了这种可能性.
current_pos = "POINT (13.39318248760133 52.52908798020595)" 到字段-继续进行,没有错误,但是又产生了另一个像上面一样难以理解的十六进制字符串.

Instead of current_pos yielding e. g. #<RGeo::Geographic::SphericalPointImpl:0x22fabdc "POINT (13.39318248760133 52.52908798020595)"> I would get 0101000020E6100000FFDD958664C92A403619DEE6B2434A40. It looked like the activerecord-postgis-adapter was not installed, or installed badly, but I eliminated that possibility by testing for the existence of data type RGeo::Feature::Point and by test-assigning
current_pos = "POINT (13.39318248760133 52.52908798020595)" to the field - which proceeded without error but then yielded another incomprehensible hex string like the above.

另外,奇怪的是,POSTGIS在数据库中可以正常工作,例如为ST_DISTANCE查询提供正确的结果.因此,这是一个非常有限的问题,其中写入,写入解析(从Point到hex格式),通过SQL操作以及读取全部有效,而只有读取后的解析无效.

Also, strangely enough, POSTGIS was working correctly within the database, e.g. giving correct results for a ST_DISTANCE query. A very limited problem thus, where writing, writing-parsing (from Point to hex format), manipulating by SQL and reading all worked, only the parsing upon read didn't.

当我尝试使用迁移以确保数据库列的类型正确时,迁移失败,给出

When I tried to use migrations to ensure the database column would have the correct type, the migrations failed, giving

undefined method `st_point' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x00000005cb80b8>

推荐答案

我花了几个小时尝试各种解决方案,甚至从头开始重新安装服务器,仔细检查了所有内容的版本号,然后安装了更新版本的Ruby和一个稍旧的POSTGIS版本(以匹配我的其他环境),导出数据库并从一个干净的数据库开始,依此类推.在完成迁移并遇到未定义的方法st_point"错误之后,我终于能够通过Google找到解决方案,最终解决了Github问题,这真的很简单:

I spent several hours trying all kinds of solutions, even re-installing the server from scratch, double-checking version numbers of everything, installing a slightly newer version of Ruby and a slightly older version of POSTGIS (to match my other environment), exporting the database and starting with a clean one, and so on. After I had done migrations and arrived at the "undefined method st_point" error, I was finally able to find the solution via Google, way down in a Github issue, and it's really simple:

在config/database.yml中,将postgres://替换为数据库URL中的postgis://.如果您使用的是Heroku,则可能需要进行一些丑陋的操作:

In config/database.yml, swap out postgres:// for postgis:// in the database url. If you're using Heroku, this may require some ugly manipulation:

production:
  url: <%= ENV.fetch('DATABASE_URL', '').sub(/^postgres/, "postgis") %>

太傻了...

这篇关于“未知OID"的来源是什么? Rails中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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