Jos*_*ore 10 migration ruby-on-rails jruby 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
Run Code Online (Sandbox Code Playgroud)
这是它在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"
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
'ENGINE=MyISAM'
进入架构?add_index "notes", ["title", "body"], :name => "title"
?以及如何强制迁移将其作为执行语句保留?感谢Christian Lescuyer的回答.但是,当我尝试这个没有改变.我取消注释了config.active_record ...行,但我的架构没有改变.我已经尝试了jruby和ruby 1.8.6上的rails 2.2.2和edge rails,架构没有变化.谁能告诉我我做错了什么?
Pet*_*aat 10
一旦我设置,我也期望看到一个新的.sql文件出现在"rake db:migrate"之后
config.active_record.schema_format = :sql
Run Code Online (Sandbox Code Playgroud)
在config/environment.rb中.
然而,显然这不是它的工作方式.我必须明确地这样做以获取db/[development | test | production] _structure.sql文件:
rake db:structure:dump
Run Code Online (Sandbox Code Playgroud)
当我使用外键约束时,我使用SQL格式进行迁移.在environment.rb中:
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
config.active_record.schema_format = :sql
Run Code Online (Sandbox Code Playgroud)
只是对Rails 3(目前的beta 4)上的更新--Christian的解决方案仍然是正确的,只有正确的放置行的位置config/application.rb
,在Application
类的范围内,应该在以Rails项目命名的模块中定义.
归档时间: |
|
查看次数: |
6261 次 |
最近记录: |