Rails模式创建问题 [英] Rails Schema creation problem

查看:86
本文介绍了Rails模式创建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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'放入架构?
  • 为什么我的execute语句变成add_index "notes", ["title", "body"], :name => "title"?以及如何强制迁移将其保留为执行语句?
  • 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和ruby 1.8.6中使用rails 2.2.2和edge rails进行了尝试,并且架构中没有更改.有人可以告诉我我在做什么错吗?

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模式创建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆