我已經爲我的遷移:schema.rb指數從個體遷移指數不同
class CreateCategories < ActiveRecord::Migration
def up
create_table :categories do |t|
t.integer :parent_id
t.string :title, :null => false
end
execute('CREATE UNIQUE INDEX ix_categories_root_title ON categories (title) WHERE parent_id IS NULL')
end
def down
drop_table :categories
end
end
但是當我偷看進入DB/schema.rb我看到這個:
ActiveRecord::Schema.define(:version => 20110808161830) do
create_table "categories", :force => true do |t|
t.integer "parent_id"
t.string "title", :null => false
end
add_index "categories", ["title"], :name => "ix_categories_root_title", :unique => true
end
這顯然不是一回事,也不正確。無論如何強制schema.rb創建相同的索引?我在Rails 3.1之前使用postresql。
我是在軌道上3.1預PostgreSQL的 – sthapit
Rails的只支持一組基本的數據庫引擎的功能,所以唯一的解決辦法是轉儲在SQL中的架構。唯一的缺點是丟失可讀的模式,但你一定會擁有所有的高級索引。 – iafonov
即使在application.rb中添加了「config.active_record.schema_format =:sql」後,我仍無法在sql中創建模式。有人可以幫忙嗎? http://stackoverflow.com/questions/7034977/how-to-create-schema-in-sql – sthapit