Solution if you delete the migration file in the up state

Introduction

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.

Conclusion

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.

Summary

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

Solution if you delete the migration file in the up state
[Rails] Delete the migration file
Completely delete the migration file that you failed to delete
How to delete the wrong migration file
How to delete the migration file NO FILE
If you want to recreate the instance in cloud9
If you make a mistake in the description location of Gem, delete Gemfile.lock once.
The migration file is duplicated
[PostgreSQL] If you want to delete the Rails app, delete the database first!
If you want to include the parent class in Lombok's @builder
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
Unzip the zip file in Java
Memo: [Java] If a file is in the monitored directory, process it.
If you have trouble with the character code problem in Myanmar (Burmese)
What to do when you want to delete a migration file that is "NO FILE"
If you want to satisfy the test coverage of private methods in JUnit
Solution when you get the error Webpacker :: Manifest :: MissingEntryError in Devise :: Sessions # new
What to do if the changes are not reflected in the jar manifest file
Hey hey validation should be written in either the model or the migration file yo
Be careful about upgrade if you use | etc. in the URL of Tomcat