Home>

We are currently deploying apps created with rails to heroku.
I am proceeding with reference to the article on how to deploy qiita, but I got an error with "heroku run rails db: migrate".
Qiita article, "I can fix it if I do this" did not fix, so I would like to ask a detailed person
.

Error message
$heroku run rake db: migrate
-create_table (: movie_chapters)
D, [2019-12-04T07: 45: 57.333169 # 4] DEBUG-: (15.1ms) CREATE TABLE "movie_chapters" ("id" bigserial primary key, "movie_id" bigint, "chapter_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_6c759d08a2"
FOREIGN KEY ("movie_id")
  REFERENCES "movies" ("id")
, CONSTRAINT "fk_rails_91e9df7e5b"
FOREIGN KEY ("chapter_id")
  REFERENCES "chapters" ("id")
)
D, [2019-12-04T07: 45: 57.334458 # 4] DEBUG-: (1.1ms) ROLLBACK
D, [2019-12-04T07: 45: 57.335852 # 4] DEBUG-: (1.2ms) SELECT pg_advisory_unlock (205462650132500460)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG :: UndefinedTable: ERROR: relation "chapters" does not exist
: CREATE TABLE "movie_chapters" ("id" bigserial primary key, "movie_id" bigint, "chapter_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_6c759d08a2"
FOREIGN KEY ("movie_id")
  REFERENCES "movies" ("id")
, CONSTRAINT "fk_rails_91e9df7e5b"
FOREIGN KEY ("chapter_id")
  REFERENCES "chapters" ("id")
)
/app/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:75:in `async_exec '
.... Omitted ...
/ app/bin/bundle: 3: in `<main>'
Tasks: TOP =>db: migrate
(See full trace by running task with --trace)

Is it said that there is no intermediate tableable?
It works fine locally and it's one-to-many, so I don't think it's necessary ...

"$heroku db: migrate: status" result

$heroku rake db: migrate: status
 Status Migration ID Migration Name
--------------------------------------------------
D, [2019-12-05T04: 45: 14.718821 # 4] DEBUG-: (4.4ms) SELECT "schema_migrations". "Version" FROM "schema_migrations" ORDER BY "schema_migrations". "Version" ASC
   up 20191124052710 Create movies
  down 20191124101254 Create movie chapters
  down 20191125043848 Movie chapters
  down 20191125050422 Rename movie id id colmn to chapters
  down 20191125122421 Change data name to chapter
  down 20191126044604 Change data kana to chapter
  down 20191126112211 Change data name to movie
  down 20191126114227 Change data youtube id to movie
  down 20191127143625 Change data name to movie 20191127
  down 20191127143700 Change data name to chapters 20191127

I searched for errors, but I didn't understand a lot of English articles.

↓ Referenced articles
[For beginners] How to reliably deploy rails app using heroku [final version]