Rails 3.2.6&通过迁移创建数据库视图 [英] Rails 3.2.6 & database views creation through migrations
问题描述
我正在使用Rails 3.2.6,我需要创建一个数据库VIEW.像往常一样,我创建了一个迁移,然后尝试使用execute方法实现目标.
I'm using rails 3.2.6 and I need to create a database VIEW. As usual I created a migration and I tried to achieve the goal using the execute method.
不幸的是,迁移会生成一个表,而不是视图.为什么?
Unfortunately the migration generates a table, not a view. Why?
非常感谢, 毛罗(Mauro)
Many thanks in advance, Mauro
更新:
我想要一些如下的东西:
I would like to have something as follows:
class CreateMyView < ActiveRecord::Migration
def self.up
execute <<-SQL
CREATE VIEW my_view AS SELECT ...
SQL
end
def self.down
execute <<-SQL
DROP VIEW my_view
SQL
end
end
不幸的是,此迁移创建了一个表...
Unfortunately this migration creates a table...
更新: 先前的代码有效!我正在执行rake db:reset而不是rake db:migrate:reset(我的错误)
UPDATE: the previous code works! I was executing rake db:reset instead of rake db:migrate:reset (my mistake)
推荐答案
我制作了一个名为 rails_db_views 与Rails 4兼容,并且仍在维护.
I've made a gem called rails_db_views which is compatible with Rails 4, and still maintained.
此致
茶碱.
这篇关于Rails 3.2.6&通过迁移创建数据库视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!