当到达create_view迁移文件时,耙中止

时间:2019-04-04 20:10:42

标签: ruby-on-rails ruby rubygems

我正在尝试让一些代码在本地运行。但是当我跑步时遇到了一个问题:

rake db:create db:migrate db:seed --trace

使用Postgres。

我们附带了一个宝石风景区,它使用create_view创建数据库视图,但是由于某种原因,当迁移到达创建视图的迁移文件时,出现以下错误:

steve-vmn:ss steve$ rake db:create db:migrate db:seed --trace
RAILS_GROUPS is unset; defaulting to web,worker
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
Database '22_development' already exists
Database '22_test' already exists
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config 
** Execute db:migrate
== 20170816124642 CreateStations: migrating ======================
-- create_view(:stations)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

No such file or directory @ rb_sysopen - /Users/steve/Ss/ss/db/views/stations_v01.sql
/Users/steve/.rvm/gems/ruby-2.4.1/gems/scenic-1.5.1/lib/scenic/definition.rb:10:in `read'
/Users/steve/.rvm/gems/ruby-2.4.1/gems/scenic-1.5.1/lib/scenic/definition.rb:10:in `to_sql'

Rake文件:

class CreateStations < ActiveRecord::Migration[5.0]
  def change
    create_view :stations
  end
end

我似乎在任何地方都找不到类似的错误。

2 个答案:

答案 0 :(得分:0)

根据错误消息和风景秀丽的文档,您需要在db/views/stations_v01.sql中定义一个SQL视图。有关示例,请参见以下链接。

https://github.com/scenic-views/scenic#great-how-do-i-create-a-view

答案 1 :(得分:0)

查看文档:{​​{3}}

如错误日志中所述,不存在文件:运行迁移后出现的db / views / stations_v01.sql。

  rails generate scenic:view stations
  create  db/views/stations_v01.sql
  create  db/migrate/[TIMESTAMP]_create_stations.rb

之后

使用定义您的视图的SQL语句编辑db / views / stations_v01.sql文件。