相关文章推荐
强悍的水煮肉  ·  PyQt5 ...·  1 年前    · 
傲视众生的苦咖啡  ·  ViewPager, ...·  2 年前    · 
含蓄的人字拖  ·  前端跨域整理 - 知乎·  3 年前    · 
豪爽的肉夹馍  ·  alertmanager ...·  3 年前    · 
9
8

More than 3 years have passed since last update.

[PG::UndefinedTable: ERROR: relation "XXXXXX" does not exist] への対応

Last updated at Posted at 2019-04-05

heroku run rails db:migrate を行うと、こんなエラーがでた

PG::UndefinedTable: ERROR:  relation "param_types" does not exist
: CREATE TABLE "param_values" ("id" bigserial primary key, "name" character varying, "presentation" character varying, "param_type_id" bigint, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_e74ade1df5"
FOREIGN KEY ("param_type_id")
  REFERENCES "param_types" ("id")

ParamValueというテーブルを作ろうとしたら、
その中でParamTypeというテーブルのid(=param_types.id)が参照されている。

しかしParamTypeというテーブルは存在しない(=UndefinedTable)ので、
ParamValueより先に作ってください、ということ。

ローカルでmigrationできても、どうやらherokuでは
migration fileは日付順にmigrateされるらしい。

ParamValueよりも先にParamTypeが作られるよう、
手動でmigration fileの日付を変更し、
ローカルで正常にmigrateされるのを確認したあと、
herokuにpushした。

rails db:drop
→この時点でmigration fileの日付を変更してよい
  • rails db:create
  • rails db:migrate
  • 問題なければherokuにpush
  • heroku pg:reset DATABASE
  • heroku run rails db:migrate
  • Register as a new user and use Qiita more conveniently

    1. You get articles that match your needs
    2. You can efficiently read back useful information
    What you can do with signing up
    8