简体   繁体   中英

How does rails know I have a pending migration?

I get that rails uses timestamps in the migration filenames. How does it utilize those to determine what migrations have been run so far and what still needs to be run? Is there a value stored somewhere that lets it know the last migration that was run?

In your database, there's a table called schema_migrations that keeps track of it. It's maintained automatically by rails, and has a single column called version . That column holds the date-time stamp of a migration, and each row represents a migration that's been already run.

So, Rails can look at all your 'migration' files in your app, figure out which ones do not yet have a corresponding row in the schema_migrations table, and run them (adding a new row to the schema migrations table, for each migration, as it runs)

Here's an example of the content of a schema_migrations table.

迁移

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM