ruby-on-rails – 无法运行rake db:使用Railscast示例在Rails中
发布时间:2020-12-17 01:19:57 所属栏目:百科 来源:网络整理
导读:我正在跟随Ryan Bates的 excellent tutorial使用Rails中内置的PostgresQL全文搜索.我目前正在使用pg_search gem un-indexed没问题,但我需要提高性能.我正在使用指定了“英语”字典的tsvector. 我正在使用PostgreSQL版本9.1.4 根据Ryan的说明,我使用此代码运
我正在跟随Ryan Bates的
excellent tutorial使用Rails中内置的PostgresQL全文搜索.我目前正在使用pg_search gem un-indexed没问题,但我需要提高性能.我正在使用指定了“英语”字典的tsvector.
我正在使用PostgreSQL版本9.1.4 根据Ryan的说明,我使用此代码运行了一个新的迁移,指定了我想要创建的两个新索引.首先是架构: create_table "references",:force => true do |t| t.string "title" t.string "type" t.datetime "created_at",:null => false t.datetime "updated_at",:null => false t.string "public_url" t.string "content_type" t.integer "file_size" t.text "overview" t.text "body" t.text "full_text" t.integer "folder_id" end 我的迁移看起来像这样: def up execute "create index references_title on references using gin(to_tsvector('english',title))" execute "create index references_full_text on references using gin(to_tsvector('english',full_text))" end def down execute "drop index references_title" execute "drop index references_full_text" end 我也继续在application.rb中取消注释:sql选项 config.active_record.schema_format = :sql 我继续得到相同的rake中止错误: == AddSearchIndexesToReferences: migrating =================================== -- execute("CREATE INDEX references_title on references using gin(to_tsvector('english',title))") rake aborted! An error has occurred,this and all later migrations canceled: PG::Error: ERROR: syntax error at or near "references" LINE 1: CREATE INDEX references_title on references using gin(to_tsv... ^ : CREATE INDEX references_title on references using gin(to_tsvector('english',title)) 解决方法
REFERENCES是与
foreign keys一起使用的关键字,因此除非您双引号,否则不能将其用作表名:
def up execute %q{create index references_title on "references" using gin(to_tsvector('english',title))} execute %q{create index references_full_text on "references" using gin(to_tsvector('english',full_text))} end 您还必须在SQL代码段中使用它时双重引用该表名称.如果正在构建SQL,ActiveRecord将为您做引用.如果您希望在许多SQL代码段中使用表名,那么我建议您重命名该表,以便您不必关心引用问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |