7

我在 Rails 2.3.2 应用程序中使用 MySQL 全文索引。我在迁移中通过本机 SQL 添加了索引。但是有一个已知问题会导致 schema.rb 出现问题。Rails 不理解全文索引并尝试创建普通索引。这在从 schema.rb 创建数据库时会导致错误(例如 testing、specs 等):

Mysql::Error: BLOB/TEXT column 'text' used in key specification without a key length: CREATE  INDEX `fulltext_sms` ON `sms` (`text`)

有没有办法在 Rails 2.3.2 中解决这个问题而无需猴子修补 Rails?如果没有,解决这个问题的最佳方法是什么?

谢谢!

我的迁移:

class FulltextIndexCustomersSmsMessage < ActiveRecord::Migration
  def self.up
    execute('ALTER TABLE sms ENGINE = MyISAM')
    execute('ALTER TABLE customers ENGINE = MyISAM')
    execute('CREATE FULLTEXT INDEX fulltext_sms ON sms (text(500))')
    execute('CREATE FULLTEXT INDEX fulltext_customer ON customers (fullname(255))')
  end

  def self.down
    execute('ALTER TABLE sms ENGINE = innodb')
    execute('ALTER TABLE customers ENGINE = innodb')
    execute('DROP INDEX fulltext_sms ON sms')
    execute('DROP INDEX fulltext_customer ON customers')
  end
end

架构.rb:

add_index "sms", ["text"], :name => "fulltext_sms"
4

2 回答 2

5

我认为你需要在你的 environment.rb 中设置它:

config.active_record.schema_format = :sql

这里参考:https ://rails.lighthouseapp.com/projects/8994/tickets/74-problem-with-tests-and-custom-mysql-fulltext-indexes

于 2009-05-16T18:26:46.803 回答
1

How about using one of the full-text search engines that can be easily plugged into Rails? Saves you the trouble of doing it all yourself with mysql. Two good options, that provide lots of customization, are:

于 2009-04-18T14:55:56.243 回答