This time, I failed in the migration, consulted with the mentor, and wrote a memo until the solution. I was making something like an app that counts likes with online school materials. I put in the code to count the likes and ran the migration, but apparently it didn't work.
When you run rails db: migrate
,
An error has occurred, this and all later migrations canceled:PG::UndefinedColumn: ERROR: column "likes_count" of relation "posts" does not existLINE 1: UPDATE "posts" SET "likes_count" = $1 WHERE "posts"."id" = $...
I got the error.
It was Google Translate, but it seemed to be angry that "likes_count does not exist in the post column!".
I received an instruction from a mentor saying "Please check rails db: migrate: status
. " When I check it,
database: like_app_development
Status Migration ID Migration Name
--------------------------------------------------
up 20201221071016 Devise create users
up 20201221072319 Create posts
up 20201221223916 Create likes
up 20201222001044 Add likes count to posts
down 20201222001313 Reset all post cache counters
Apparently, the likes count wasn't added well in the 20201222001044 part.
File in question,
20201222001044_add_likes_count_to_posts.rb
class AddLikesCountToPosts < ActiveRecord::Migration[6.1]
def change
add_column :posts, :likes_count, :integer, default: 0
end
end
Comment this out and roll back using the rails db: rollback
command.
Then comment out and run rails db: migrate
again.
The migration was done correctly, and we were able to confirm the operation properly! !! : clap :: clap ::
I think the failure this time was probably because I had migrated before putting in likes_count. When migrating, I would like to confirm the files properly before executing. Even so, I was able to solve it immediately with the quick response of the mentor. Thank you, thank you!
Recommended Posts