exactly what does rake db:migrate do?

前端 未结 3 1428
孤独总比滥情好
孤独总比滥情好 2021-02-07 00:58

Does rake db:migrate only add new migrations, or does it drop all migrations/changes and build everything new?

I think rake is throwing an error because it is trying to

相关标签:
3条回答
  • 2021-02-07 01:18

    When you use rails migrations, a table called schema_migrations is automatically created, which keeps track of what migrations have been applied, by storing the version number of each migration (this is the number that prefaces the migration name in the file name, ie db/migrate/_20090617111204__migration.rb). When you run rake db:migrate to migrate up, only migrations which have not been run previously (ie. their version is not contained in the table) will be run (for this reason, changing a migration that's already been executed will have no effect when running db:migrate). When migrating down, all versions found in schema_migrations that are greater than the version you are rolling back to will be undone.

    0 讨论(0)
  • 2021-02-07 01:34

    A migration means that you move from the current version to a newer version (as is said in the first answer). Using rake db:migrate you can apply any new changes to your schema. But if you want to rollback to a previous migration you can use rake db:rollback to nullify your new changes if they are incorrectly defined. Caution: by doing so your data will be lost.

    0 讨论(0)
  • 2021-02-07 01:39

    Everytime you create a migration using scripts (like script/generate model ...) a new migration is added to the correct directory ready to be synched with the real database.

    Actually rake db:migrate just checks which missing migrations still need to be applied to the database without caring about the previouse ones.

    Of course if you modify the database using other ways is common to obtain out-of-synch things because as you said you can find yourself applying a migration to something that is changed underneath.

    0 讨论(0)
提交回复
热议问题