使用特定于数据库的数据类型进行Rails迁移

编程入门 行业动态 更新时间:2024-10-27 17:15:46
本文介绍了使用特定于数据库的数据类型进行Rails迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在运行Rails迁移,在其中我要添加特定于Postgres的数据类型tsvector.它以Postgres期望的内置文本搜索功能的形式保存搜索信息.

I'm currently running a Rails migration where I am adding a datatype specific to Postgres, the tsvector. It holds search information in the form that Postgres expects for its built-in text searching capabilities.

这是我的迁移行:

t.column "search_vectors", :tsvector

一切似乎都可以正常工作,并且搜索也可以正常工作.但是,当我打开schema.rb时,这就是我得到的:

Everything seems to be working fine, and the search works with it. However, when I opened up schema.rb, this is what I got:

Could not dump table "users" because of following StandardError Unknown type 'tsvector' for column 'search_vectors'

这使我无法在用户表上运行单元测试,并且由于schema.rb应该是我数据库的权威定义,这使我感到非常危险.

This is preventing me from running unit tests on the user table, and also strikes me as really dangerous looking given that the schema.rb is supposed to be the authoritative definition of my database.

我注意到有许多Rails插件似乎使用了与我期望的相同的tsvector存储方法,例如tsearchable.我真的只是在没有测试并且没有对数据库进行权威定义的情况下坚持吗?

I notice there are a number of Rails plugins that seem to use the same approach of storing the tsvector like I would expect, such as tsearchable. Am I really just stuck without testing and without an authoritative definition of my database?

推荐答案

对于在此页面上发生的任何人,仅供参考,我通过将其添加(实际上取消注释)到我的Rails配置中来解决此问题: config.active_record.schema_format =:sql

FYI for anyone who happens across this page, I fixed this by adding this (actually uncommenting it) to my Rails config: config.active_record.schema_format = :sql

更多推荐

使用特定于数据库的数据类型进行Rails迁移

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

发布评论

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

>www.elefans.com

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