schema.rb指数从个体迁移指数不同

编程入门 行业动态 更新时间:2024-10-12 22:30:13
本文介绍了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我看到这个:

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指数从个体迁移指数不同

本文发布于:2023-10-18 04:27:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503105.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指数   个体   schema   rb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!