LoginSignup
1
2

More than 3 years have passed since last update.

schema.rbにマイグレーションファイルが反映されない!

Last updated at Posted at 2020-02-14

開発環境

ubuntu(WSL)
Rails 5.2
Postgresql

想定エラー内容

ActionView::Template::Error (PG::UndefinedColumn: ERROR:  column tasks.user_id does not exist
LINE 1: SELECT "tasks".* FROM "tasks" WHERE "tasks"."user_id" = $1 O...

原因

一概には言えないですが、おそらくrails:db migrateした後にマイグレーションファイルを書き換えている。

対処法

rails db:migrate:statusで反映されているか確認する。
upは反映済み。downは未反映。

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200213054056  Create users
   up     20200214132021  Add user id to tasks

rails db:rollbackで戻す。
マイグレーションファイルを書き換えて再び、rails db:migrateを実行する。

参考文献

1
2
0

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
  3. You can use dark theme
What you can do with signing up
1
2