現在railsでWEBアプリを作成し、Herokuにデプロイしているのですが、本番環境でエラーが出たので、
見直したところ、
heroku run rails db:migrate
した際に以下のエラーが出ている事を見つけました。
heroku run rails db:migrate Running rails db:migrate on ⬢ teterako... up, run.2755 (Free) D, [2020-10-11T13:11:01.732435 #4] DEBUG -- : (1.2ms) SELECT pg_try_advisory_lock(3591403873564692675) D, [2020-10-11T13:11:01.752278 #4] DEBUG -- : (2.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC I, [2020-10-11T13:11:01.753656 #4] INFO -- : Migrating to ChangeDataUserIdToPosts (20200930145224) D, [2020-10-11T13:11:01.757006 #4] DEBUG -- : (1.1ms) BEGIN == 20200930145224 ChangeDataUserIdToPosts: migrating ========================== -- change_column(:posts, :title, :integer) D, [2020-10-11T13:11:01.759452 #4] DEBUG -- : (2.0ms) ALTER TABLE "posts" ALTER COLUMN "title" TYPE integer D, [2020-10-11T13:11:01.760793 #4] DEBUG -- : (1.1ms) ROLLBACK D, [2020-10-11T13:11:01.762427 #4] DEBUG -- : (1.3ms) SELECT pg_advisory_unlock(3591403873564692675) rails aborted! StandardError: An error has occurred, this and all later migrations canceled: PG::DatatypeMismatch: ERROR: column "title" cannot be cast automatically to type integer HINT: You might need to specify "USING title::integer". : ALTER TABLE "posts" ALTER COLUMN "title" TYPE integer
以前にPostモデルのtitileカラムがなぜか数字しか出ず、データ型をtextからstringに変えたことが原因だと思い、Postモデルのtitileカラムを削除してみましたがこのエラーは消えず、、、
そして、新しくPostモデルに新しくtitleカラムをデータ型integerで追加してみましたがこのエラーは消えません。調べてみても原因がわからず、このエラーの解決法、原因を教えていただけたら幸いです。
よろしくお願いいたします。
db/schema.rb
1# This file is auto-generated from the current state of the database. Instead 2# of editing this file, please use the migrations feature of Active Record to 3# incrementally modify your database, and then regenerate this schema definition. 4# 5# Note that this schema.rb definition is the authoritative source for your 6# database schema. If you need to create the application database on another 7# system, you should be using db:schema:load, not running all the migrations 8# from scratch. The latter is a flawed and unsustainable approach (the more migrations 9# you'll amass, the slower it'll run and the greater likelihood for issues). 10# 11# It's strongly recommended that you check this file into your version control system. 12 13ActiveRecord::Schema.define(version: 2020_10_11_130211) do 14 15 create_table "likes", force: :cascade do |t| 16 t.integer "word_user_id" 17 t.integer "word_id" 18 t.datetime "created_at", null: false 19 t.datetime "updated_at", null: false 20 end 21 22 create_table "posts", force: :cascade do |t| 23 t.text "content" 24 t.string "url" 25 t.string "next_url" 26 t.string "class_type" 27 t.string "image_url" 28 t.string "user_id" 29 t.datetime "created_at", null: false 30 t.datetime "updated_at", null: false 31 t.string "taiwan_beginner_1" 32 t.string "taiwan_beginner_cleared" 33 t.text "posts_title" 34 t.integer "title" 35 end 36 37 create_table "taiwan_beginner_1_posts", force: :cascade do |t| 38 t.text "content" 39 t.datetime "created_at", null: false 40 t.datetime "updated_at", null: false 41 t.integer "user_id" 42 end 43 44 create_table "taiwanbeginner1posts", force: :cascade do |t| 45 t.text "content" 46 t.integer "user_id" 47 t.datetime "created_at", null: false 48 t.datetime "updated_at", null: false 49 end 50 51 create_table "users", force: :cascade do |t| 52 t.string "provider" 53 t.string "uid" 54 t.string "name" 55 t.string "email" 56 t.string "image" 57 t.string "oauth_token" 58 t.datetime "oauth_expires_at" 59 t.datetime "created_at", null: false 60 t.datetime "updated_at", null: false 61 t.string "taiwan_daily_conversation_purchased" 62 t.string "taiwan_beginner_cleared" 63 t.string "taiwan_intermediate_cleared" 64 t.string "taiwan_daily_conversation_cleared" 65 t.string "taiwan_before_studying_abroad_cleared" 66 t.string "taiwan_before_studying_abroad_purchased" 67 t.string "taiwan_beginner_1_cleared" 68 t.string "taiwan_beginner_2_cleared" 69 end 70 71 create_table "words", force: :cascade do |t| 72 t.string "word_type" 73 t.string "word_user_id" 74 t.string "content" 75 t.string "meaning" 76 t.string "pronunciation" 77 t.datetime "created_at", null: false 78 t.datetime "updated_at", null: false 79 end 80 81end 82
あなたの回答
tips
プレビュー