ActiveRecord中的自定义数据库类型

编程入门 行业动态 更新时间:2024-10-23 01:39:55
本文介绍了ActiveRecord中的自定义数据库类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将Rails 3.1.1与PostgreSQL 9.1和 earthdistance模块一起使用。 为了能够正确计算不同位置之间的距离,我在分支表。

I am using Rails 3.1.1 with PostgreSQL 9.1 and the earthdistance module. To be able to calculate the distance between different locations properly, I have setup a column with the earth type in my branches table.

我现在遇到的问题是使用该表的Rails应用程序不了解地球类型,因此我将其获取 db / schema.rb :

The problem I am experiencing now is that my Rails application that uses this table does not understand the earth type and thus I am getting this in my db/schema.rb:

# Could not dump table "branches" because of following StandardError # Unknown type 'earth' for column 'location'

这是有问题的,因为现在我无法从schema.rb创建测试数据库

This is problematic since now I can't create my test database from the schema.rb.

如何将这种类型添加到AR或使其忽略该列?

推荐答案

尝试一下:

更改您的config / application.rb

Change you config/application.rb

config.active_record.schema_format = :sql

此将输出格式更改为本地PostgreSQL SQL格式schema.rb w将被禁用,将生成一个新文件/db/config/structure.sql

This will change the output format to the native PostgreSQL SQL format, schema.rb will be disabled and a new file will be generated /db/config/structure.sql

更多推荐

ActiveRecord中的自定义数据库类型

本文发布于:2023-10-23 22:48:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522230.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   类型   数据库   ActiveRecord

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!