[Rails] When deploying Heroku you can't define an already defined column'''Coping method

I didn't notice it when developing in the local environment, but I had various problems when deploying heroku, so I will write it as a memorandum.

The beginning of the matter

I got this error and couldn't migrate.

rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
you can't define an already defined column 'name'.

Try resetting the database once

Reset the database once and re-migrate.

$ rails db:migrate:reset

And again my great

$ rails db:migrate

Then, I got this error.

StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column "user_id" of relation "scores" does not exist

I am migrating in the order of the time stamps, but I got an error at a certain migrating file. There were various problems, but the big problem was that there was a migration file that tried to reomove a column that did not exist. I deleted it and ran the migration again and it worked fine.

Recommended Posts

[Rails] When deploying Heroku you can't define an already defined column'''Coping method
What to do if you can't find your API key after deploying to Rails heroku
An introductory book to read when you start Rails
[Rails] What to do if you can't get an error message with the errors method
What to do when you launch an application with rails