I have a bunch of migrations, but due to some weird reason, rails suddenly forgot that it has ran most of these already. Now when I try to run rake db:migrate
, rails will try to run ALL of the migrations.
How do I set the current "version number" or whatever it's called so that rails knows that "oh I already ran the first 5 migrations, I should start from the 6th one"
Migrations are a feature of Active Record that allows you to evolve your database schema over time. Rather than write schema modifications in pure SQL, migrations allow you to use a Ruby DSL to describe changes to your tables.
Every migration file that Rails generates has a timestamp that is present in the filename. This timestamp is important and is used by Rails to confirm whether a migration has run or not, as we'll see later. The migration contains a class that inherits from ActiveRecord::Migration[6.0] .
You must rollback the migration (for example with bin/rails db:rollback ), edit your migration, and then run bin/rails db:migrate to run the corrected version.
The schema_migrations
table stores the numbers for all the migrations that have been run (just the numeric part). If you fill it with all the migration numbers that you think have already run rails shouldn't try to run them again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With