ActiveRecord中的自定义数据库类型 [英] Custom Database Type in ActiveRecord
问题描述
我将Rails 3.1.1与PostgreSQL 9.1和 earthdistance模块一起使用一个>。
为了能够正确计算不同位置之间的距离,我在分支$中设置了一个
地球
类型的列c $ c>表。
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中的自定义数据库类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!