Rails Schema 创建问题 [英] Rails Schema creation problem
问题描述
我正在使用 Jruby 和 rails 2.2.2.我的问题是我的迁移未正确写入数据库架构.
I am using Jruby and rails 2.2.2. My problem is I have a migration that is not being correctly written to the database schema.
这是我的迁移:
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 中产生的内容
Here is what it produces on in 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 =>标题"
?以及如何强制迁移将其保留为执行语句?
- How do I get
'ENGINE=MyISAM'
into the schema? - Why did my execute statement become
add_index "notes", ["title", "body"], :name => "title"
? and how do I force migrations to leave it as an execute statement?
感谢 Christian Lescuyer 的回答.但是,当我尝试这个时,什么都没有改变.我取消了 config.active_record... 行的注释,但是我的架构没有改变.我已经在 jruby 和带有 rails 2.2.2 和 edge rails 的 ruby 1.8.6 上尝试过这个,并且架构没有变化.谁能告诉我我做错了什么?
Thanks to Christian Lescuyer for the answer. However, when I tried this nothing changed. I uncommented the config.active_record... line but, my schema has not changed. I have tried this in jruby and on ruby 1.8.6 with rails 2.2.2 and edge rails and there is not changes in the schema. Can anybody tell me what I am doing wrong?
推荐答案
由于我使用外键约束,我使用 SQL 格式进行迁移.在environment.rb中:
As I use foreign key constraints, I use the SQL format for migrations. In 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
这篇关于Rails Schema 创建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!