ruby-on-rails - Rails 架构创建问题

标签 ruby-on-rails jruby migration activerecord-jdbc

我正在使用 Jruby 和rails 2.2.2。我的问题是我的迁移未正确写入数据库架构。

这是我的迁移:

class CreateNotes < ActiveRecord::Migration
  def self.up
    create_table(:notes, :options => 'ENGINE=MyISAM') do |t|
      t.string :title
      t.text :body

      t.timestamps
    end

    execute "alter table notes ADD FULLTEXT(title, body)"

end

这是它在 schema.rb 中生成的内容

create_table "notes", :force => true do |t|
  t.string   "title"
  t.text     "body"
  t.datetime "created_at"
  t.datetime "updated_at"
end

add_index "notes", ["title", "body"], :name => "title"

我有两个问题:

  • 如何将 'ENGINE=MyISAM' 添加到架构中?
  • 为什么我的执行语句变成了 add_index "notes", ["title", "body"], :name => "title"?以及如何强制迁移将其保留为执行语句?

感谢克里斯蒂安·莱斯库耶的回答。然而,当我尝试这样做时,一切都没有改变。我取消了 config.active_record... 行的注释,但是我的架构没有改变。我已经在 jruby 和 ruby​​ 1.8.6 上尝试过使用 Rails 2.2.2 和 Edge Rails,并且模式没有变化。谁能告诉我我做错了什么?

最佳答案

一旦我设置,我也希望在“rake db:migrate”之后看到一个新的.sql文件出现

config.active_record.schema_format = :sql

在config/environment.rb中。

然而,显然这不是它的工作原理。我必须明确执行此操作才能获取 db/[development|test|product]_struct.sql 文件:

rake db:structure:dump

关于ruby-on-rails - Rails 架构创建问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/383058/

相关文章:

ruby-on-rails - Rails 部分表验证

migration - 未下载 - "Azure DocumentDB Data Migration Tool"

java - Cucumber 0.4.3 (cuke4duke) 与 java + maven gem 问题

ruby-on-rails - Faye in jruby on rails

ruby - 在 google appengine 上部署 ruby​​ + sinatra 应用程序

perl - 将 Perl CGI 迁移到模板工具包的策略?

entity-framework - 如何在没有硬编码 nameOrConnectionString 的情况下使用 EF CodeFirst 迁移

ruby-on-rails - Rails-api gem 分页

ruby-on-rails - Rails 加入或包含有条件的 belongs_to

ruby-on-rails - rails 查询: get all parent records based on latest child records