When I was making an app with rails, I migrated an unnecessary table and manually deleted the migration file. If you delete the migration file in the up state
 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20210116053731  ********** NO FILE **********
   up     20210118091408  Devise create users
If you get the message NO FILE and want to create the same file, I was at a loss because I was angry that "the file name already exists!", So I made a note as a memorandum.
The bottom line is that you create another migration file and give instructions to delete it. In this case, first, create a file with the Migration ID under the db directory. In the above example, 「20210116053731_sample.rb」 Create a file called. And in that state
rails db:migrate:status
And type in the terminal
 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20210116053731  Sample
  down    20210118091408  Devise create users
The file name changes like this. And in that state
rails db:rollback
By typing, the migration file will be in the down state.
Status   Migration ID    Migration Name
--------------------------------------------------
  down    20210116053731  Sample
  down    20210118091408  Devise create users
Then, after confirming that it is down, manually delete the migration file. Then you can erase the table.
I was impressed that there are various methods that there was a method of creating a new file from the Migration ID and deleting it by migrating or rolling back from there. It took about 90 minutes, so next time I can solve it in 3 minutes!
Recommended Posts