Marking Rails migrations as migrated

I solved it like this:

  1. Go to the conflicting migration file.

  2. Erase the content and save it.

  3. Run rake db:migrate

  4. Ctrl+Z the file to the previous state.

This was an special case, because I had copied the DB from another app, and I had conflicting migrations, and stuff.


You can add the timestamps of the migrations to the schema_migrations table. However why is that table missing from the database or missing the rows it needs?

It is likely to be the case that this particular migration has got half way through and failed, thus when you are trying to run it again the first part of the migration will not work as it has been done previously. This is a limitation of MySQL as it can't rollback migration changes that fail part of the way through. Postgres on the other hand can rollback structural changes to the database thus avoiding this issue.


You can also, in a Rails console, use the ActiveRecord::SchemaMigration model to add the timestamps into the schema_migrations table.

ActiveRecord::SchemaMigration.create! version: '20210724133241'

By default rake db:migrate runs all the pending migrations. So, in order to get your migrations right.. for the sake ..comment out those migrations and afterwards revert those back to normal. It will ensure that you are ok in future migrations.