質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

1554閲覧

herokuにRailsアプリをデプロイするも、stack level too deepでheroku run rake db:migrateができない。

Romay

総合スコア40

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/03/22 20:27

編集2019/03/23 20:01

前提・実現したいこと

ruby 2.3.1
Rails 4.2.6
mysql (開発環境)
postgresql(heroku)


Railsアプリをherokuにデプロイしています。
herokuの設定を終え、

terminal

1git push heroku master

がうまくいきました。
しかし、次のコマンドを打ったところでエラーがでてしました。

terminal

1heroku run rails db:migrate

発生している問題・エラーメッセージ

stack level too deepのエラーが出ています。
herokuデプロイが初めてで、今回のエラー文にうまく対処できずにいます。

terminal

1/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/exe/bundle:22:in `<top (required)>' 2/app/bin/bundle:3:in `load' 3/app/bin/bundle:3:in `<main>' 4Tasks: TOP => db:migrate => environment 5(See full trace by running task with --trace) 6Traceback (most recent call last): 7 8387: from /app/bin/bundle:3:in `<main>' 8 8386: from /app/bin/bundle:3:in `load' 9 8385: from /app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/exe/bundle:22:in `<top (required)>' 10 8384: from /app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:120:in `with_friendly_errors' 11 8383: from /app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:123:in `rescue in with_friendly_errors' 12 8382: from /app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:45:in `log_error' 13 8381: from /app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:95:in `request_issue_report_for' 14 8380: from /app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/env.rb:18:in `report' 15 ... 8375 levels... 16 4: from /app/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>' 17 3: from /app/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>' 18 2: from /app/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>' 19 1: from /app/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>' 20/app/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>': stack level too deep (SystemStackError)

該当のソースコード

Gemのバージョンが問題になるという記事がいくつかあったので、Gemfileを以下に置いておきます。

Gemfile

ruby

1source 'https://rubygems.org' 2 3 4# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5gem 'rails', '4.2.6' 6# Use mysql as the database for Active Record 7gem 'mysql2', '>= 0.3.13', '< 0.5', group: :development 8gem 'pg', group: :production 9# Use SCSS for stylesheets 10gem 'sass-rails', '~> 5.0' 11# Use Uglifier as compressor for JavaScript assets 12gem 'uglifier', '>= 1.3.0' 13# Use CoffeeScript for .coffee assets and views 14gem 'coffee-rails', '~> 4.1.0' 15# See https://github.com/rails/execjs#readme for more supported runtimes 16gem 'therubyracer', platforms: :ruby 17 18# Use jquery as the JavaScript library 19gem 'jquery-rails' 20# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 21gem 'turbolinks' 22# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 23gem 'jbuilder', '~> 2.0' 24# bundle exec rake doc:rails generates the API under doc/api. 25gem 'sdoc', '~> 0.4.0', group: :doc 26 27 28 29# Use ActiveModel has_secure_password 30# gem 'bcrypt', '~> 3.1.7' 31 32# Use Unicorn as the app server 33# gem 'unicorn' 34 35# Use Capistrano for deployment 36# gem 'capistrano-rails', group: :development 37 38group :development, :test do 39 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 40 gem 'byebug' 41end 42 43 44 45group :development do 46 # Access an IRB console on exception pages or by using <%= console %> in views 47 gem 'web-console', '~> 2.0' 48 49 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 50 gem 'spring' 51end 52 53 gem 'pry-rails' 54 gem 'compass-rails','~> 2.0' 55 gem 'sprockets', '2.11.0' 56 gem 'devise' 57 gem 'omniauth' 58 gem 'omniauth-facebook' 59 gem 'omniauth-twitter' 60 gem 'bootstrap-sass' 61 gem 'dotenv-rails' 62 gem 'paperclip' 63 gem 'omniauth-instagram' 64 gem 'instagram' 65 gem 'friendly_id' 66 gem 'font-awesome-rails' 67 gem 'zeroclipboard-rails' 68 gem 'rails-i18n' 69 gem 'google-analytics-rails' 70 gem 'carrierwave' 71 gem 'acts_as_paranoid', '~> 0.6.0' 72 gem 'rails_12factor', group: :production 73

試したこと

Heroku の assets:precompile で エラーが起きたときの調査方法
https://mittsu-blog.com/how-to-cheack-heroku-assets-precompile-error

こちらの記事にあるように、Railsのバージョンが問題になるのでしょうか。

7年前の記事ですが、rails-saasのバージョンが問題だった質問
Getting “stack level too deep” error when deploying with Capistrano, Rails 3.1 ruby 1.9.2

英語で検索しいろいろ見てみましたが、対処法が見つからず。。。

補足情報(FW/ツールのバージョンなど)

エラー文から手がかりが掴めずに困っています。

追記

schema.rb

ruby

1# encoding: UTF-8 2# This file is auto-generated from the current state of the database. Instead 3# of editing this file, please use the migrations feature of Active Record to 4# incrementally modify your database, and then regenerate this schema definition. 5# 6# Note that this schema.rb definition is the authoritative source for your 7# database schema. If you need to create the application database on another 8# system, you should be using db:schema:load, not running all the migrations 9# from scratch. The latter is a flawed and unsustainable approach (the more migrations 10# you'll amass, the slower it'll run and the greater likelihood for issues). 11# 12# It's strongly recommended that you check this file into your version control system. 13 14ActiveRecord::Schema.define(version: 20190321185800) do 15 16 create_table "images", force: :cascade do |t| 17 t.string "image", limit: 255 18 t.integer "user_id", limit: 4 19 t.datetime "created_at", null: false 20 t.datetime "updated_at", null: false 21 end 22 23 create_table "items", force: :cascade do |t| 24 t.integer "user_id", limit: 4 25 t.text "text", limit: 65535 26 t.datetime "created_at", null: false 27 t.datetime "updated_at", null: false 28 t.boolean "check", default: false 29 t.datetime "deleted_at" 30 end 31 32 add_index "items", ["deleted_at"], name: "index_items_on_deleted_at", using: :btree 33 34 create_table "users", force: :cascade do |t| 35 t.string "email", limit: 255, default: "", null: false 36 t.string "encrypted_password", limit: 255, default: "", null: false 37 t.string "reset_password_token", limit: 255 38 t.datetime "reset_password_sent_at" 39 t.datetime "remember_created_at" 40 t.datetime "created_at", null: false 41 t.datetime "updated_at", null: false 42 t.string "uid", limit: 255 43 t.string "provider", limit: 255 44 t.string "avatar_file_name", limit: 255 45 t.string "avatar_content_type", limit: 255 46 t.integer "avatar_file_size", limit: 8 47 t.datetime "avatar_updated_at" 48 t.string "nickname", limit: 255 49 t.string "description", limit: 255 50 t.string "twitter", limit: 255 51 t.string "instagram", limit: 255 52 t.string "friendly_url", limit: 255 53 end 54 55 add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree 56 add_index "users", ["friendly_url"], name: "index_users_on_friendly_url", unique: true, using: :btree 57 add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree 58 59end 60

こちらの記事にあるように、rails 4.2.6から rails 4.2.8にupdateしてみましたがエラーは解決しませんでした。。。

Ruby 2.4 and Rails 4 stack level too deep (SystemStackError)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kazto

2019/03/23 02:07

migrationに失敗しているため、/db/migrate/以下のファイルに問題があると見込まれます。内容を追記お願いします。
Romay

2019/03/23 19:34 編集

コメントありがとうございます。 /db/migrate/以下のファイルは、10個ほどのmigrationファイルと、schema.rb、seeds.rbが存在しています。migrationファイルは問題ないと思うので、schema.rbを追記しておきます。
guest

回答1

0

rails 4.2.8ではruby 2.5は対応していないと思います。
Gemfile で2.4系を指定してデプロイをお試しください。

投稿2019/03/24 02:24

ykp_yk

総合スコア654

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Romay

2019/03/24 03:33

コメントありがとうございます。 現在のバージョンは、 Ruby 2.3.1 Rails 4.2.8 です。 Ruby 2.4系にアップグレードした方がいいということでしょうか。 また、このようなバージョンのサポート関係を確認するサイト等ありますでしょうか。
ykp_yk

2019/03/24 03:58

そちらは開発環境でのrubyのバージョンになると思います。 Heroku側で使われているrubyのバージョンを確認してみてください。 $ heroku run ruby -v おそらく2.5系が使われていることと思いますので2.4系を指定する記述をGemfileに記述し、デプロイしてください。 例: ruby '2.4.5' など Herokuでは2.4.5をサポートしているようですから、ローカル開発環境もアップグレードをしておくと良いと思います。 https://devcenter.heroku.com/articles/ruby-support もし2.5系以上をお使いになるというのでしたらrails5をご利用ください。
Romay

2019/03/30 22:23

おっしゃる通り、$ heroku run ruby -vで2.5.0が使われていたので、ruby '2.4.5'に変更し、ローカル環境もrbenvを使ってruby'2.4.5'にupdateしました。 git push heroku masterをし、heroku run rails db:migrateをしたのですが、stack level too deepのエラーがまた出てしまいました。 $ heroku run ruby -vの結果は、ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]となっているのですが、エラー文には、/app/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.6/lib/active_support/~~~~~~~~~~~~~~~~~~~~ という文が続いています。 なぜ2.4.0になっているのかよくわからないのですが、何かここからわかる手がかりはありますでしょうか。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問