Fixing ActiveRecord::UnknownMigrationVersionError

Usual cause: deleting a Rails migration file without a rollback.

Error message example:

ActiveRecord::UnknownMigrationVersionError:
No migration with version number 20230815162103.

That means Rails can't find a migration file matching specific record in the schema_migrations table.

To fix this error, open DB console:

rails dbconsole

Drop the missing migration:

delete from schema_migrations where version = '20230815162103';

Type quit to exit.

Done!

Tracking missing migration:

$ bin/rails db:migrate:status
...
up     20230801199444  Create users table
up     20230801223219  Create Messages table
up     20230802211438  ********** NO FILE **********
up     20230802210508  Update users table

References:



Somewhat related: