Destroying Invalid Migration

New to Rails here. A couple of questions about migration:

  • I created a migration that I no longer want. I want to delete it. Is the correct command just rails destroy migration AddMyColumnToMyModel ?

  • Let's say I'm wrong that the name of the migration I want to destroy ... That's what happens when I try to destroy a migration that does not exist.

     $ rails destroy migration Blah invoke active_record remove migration.rb 

    It talks about removing migration.rb ... is that bad?

+4
source share
1 answer
  • Of course, the right team. Just be careful: if you actually did an unwanted migration using rake db:migrate to commit changes to your database, be sure to do this before anything else:

     rake db:rollback 

    What this means is, run the down method on the last migration. He does exactly the same thing:

     rake db:migrate:down VERSION=20130529014413 

    If the version number matches the number of your last migration. It can also accept the STEP parameter if you need to drop a bunch of migrations, and not just one:

     rake db:rollback STEP=3 

    Of course, if you just created an unwanted migration and never started it, there is no need to roll back anything. You can use the command you published or manually delete the corresponding file to get rid of it.

    Source: http://guides.rubyonrails.org/migrations.html#rolling-back

  • Do not worry that you are not doing anything with your code.

+5
source

Source: https://habr.com/ru/post/1483602/


All Articles