gpt4 book ai didi

ruby-on-rails - PG::UndefinedTable: 错误:关系 "services"不存在 LINE 1: SELECT "services".* FROM "services"

转载 作者:行者123 更新时间:2023-11-29 13:17:54 27 4
gpt4 key购买 nike

我在使用 whenever gem 时遇到了一些问题。我创建了一个 rake 任务,当我自己启动它时它工作得很好但是当我在日志中收到以下消息时尝试自动执行它:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "services" does not exist
LINE 1: SELECT "services".* FROM "services"
^
: SELECT "services".* FROM "services"
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `async_exec'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `block in exec_no_cache'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activesupport-5.0.6/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `exec_no_cache'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:585:in `execute_and_clear'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:103:in `exec_query'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/database_statements.rb:377:in `select_prepared'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/database_statements.rb:39:in `select_all'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/connection_adapters/abstract/query_cache.rb:95:in `select_all'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/querying.rb:39:in `find_by_sql'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation.rb:706:in `exec_queries'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation.rb:583:in `load'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation.rb:260:in `records'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/activerecord-5.0.6/lib/active_record/relation/delegation.rb:38:in `each'
/Users/Naekh/code/yoando/statuschecker/statuschecker/lib/tasks/fb_ping.rake:5:in `block (2 levels) in <top (required)>'
/Users/Naekh/code/yoando/statuschecker/statuschecker/lib/tasks/rake_them_all.rake:4:in `block (2 levels) in <top (required)>'
/Users/Naekh/.rvm/gems/ruby-2.4.1/gems/rake-12.1.0/exe/rake:27:in `<top (required)>'
/Users/Naekh/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/Users/Naekh/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'

这是命名问题吗?我检查并仔细检查,但我是否遗漏了什么?

我的环境是开发。

这是我的 schedule.rb:

set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
every 2.minutes do
rake 'check:all', :environment => 'development'
end

和我的模式:

ActiveRecord::Schema.define(version: 20170922073721) do

enable_extension "plpgsql"

create_table "pings", force: :cascade do |t|
t.boolean "up"
t.integer "service_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["service_id"], name: "index_pings_on_service_id", using: :btree
end

create_table "services", force: :cascade do |t|
t.string "name"
t.string "web_api"
t.string "json_path"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_foreign_key "pings", "services"
end

这是我的模型:- 服务.rb

class Service < ApplicationRecord
has_many :pings, dependent: :destroy
validates :name, uniqueness: true, presence: true
validates :web_api, uniqueness: true, presence: true
end
  • ping.rb

    类 Ping < ApplicationRecord 属于:服务结束

最佳答案

因此,由于您的评论,我找到了问题所在。

Cron 正在发送这个:

/bin/bash -l -c 'cd /Users/Naekh/code/yoando/statuschecker/statuschecker && RAILS_ENV=production bundle exec rake check:all --silent >> log/cron_log.log 2>> log/cron_error_log.log'

如您所见,他正在将其发送到生产环境,即使在我的日程安排中也是如此:

set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
every 2.minutes do
rake 'check:all', :environment => 'development'
end

我告诉他将它发送到开发环境。我现在需要找到一种方法来迫使他进入那种环境,就像我运行时一样:

/bin/bash -l -c 'cd /Users/Naekh/code/yoando/statuschecker/statuschecker && RAILS_ENV=environment bundle exec rake check:all --silent >> log/cron_log.log 2>> log/cron_error_log.log'

有效

我更新了 cronjob 环境:

whenever --update-crontab --set environment='development'

现在一切顺利

关于ruby-on-rails - PG::UndefinedTable: 错误:关系 "services"不存在 LINE 1: SELECT "services".* FROM "services",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46400787/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com