我已经为我的迁移:
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我看到这个:
But when I peeked into db/schema.rb I saw this instead:
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创建相同的索引?我使用postresql在Rails 3.1 pre。
Which obviously isn't the same thing and incorrect. Is there anyway to force schema.rb to create the same index? I'm using postresql with Rails 3.1 pre.
推荐答案时,他说,让你的application.rb中的文件该配置选项iafonov是正确的:
iafonov was correct when he said to enable this config option in your application.rb file:
config.active_record.schema_format = :sql
然而,简单地实现预期此功能不起作用。它不会自动生成一个 schema.sql文件文件。相反,你可以使用耙分贝:结构:转储这将创建一个 structure.sql 文件。结构:负载
However, simply enabling this feature does not work as expected. It will not automatically generate a schema.sql file. Instead you can use rake db:structure:dump which will create a structure.sql file. Then you can load it with rake db:structure:load
这里有一个很好的解释:schema.sql没有创造,甚至设置schema_format =后:SQL
There's a nice explanation here: schema.sql not creating even after setting schema_format = :sql
更多推荐
schema.rb指数从个体迁移指数不同
发布评论