rake db:schema:load not populating schema_migrations table rake db:schema:load not populating schema_migrations table ruby-on-rails ruby-on-rails

rake db:schema:load not populating schema_migrations table


Per D. Patrick, answering my own question:

So the end result was that another developer had installed activerecord-nulldb-adapter, which monkey patches ActiveRecord::Schema.define and doesn't run initialize_schema_migrations_table() or assume_migrated_up_version(). I uninstalled the gem, ran my db:schema:load just fine.


Try to run the command with the trace flag

rake db:schema:load --trace

By the end of the log you should see lines

-- initialize_schema_migrations_table()   -> 0.0045s

Also, it worth to check does you test suit generate table from schema and the schema_migrations table correctly.


I had a similar issue and Google brought me here. It's not the exact same problem as yours but I'll write this up in case it helps anyone who ends up here, as I couldn't find anything else.

In brief: rails db:schema:load wasn't setting my schema_migrations table correctly - when I ran rails db:migrate:status, the most recent migration was marked as down, even though it was clear from looking in the DB that the migration had actually been run. This meant that when I tried to do anything in my app I got an "migrations are still pending" error.

Turns out that the problem was db/schema.rb. At the top of the file, the line ActiveRecord::Schema.define(version: 20180803094506) do was incorrect. Thanks to a mix-up in my source control, 20180803094506 was the wrong timestamp. I fixed the problem by changing this timestamp to that of my most recent migration (i.e. the first part of the name of the last file in db/migrate.)

(The relevant bit of the Rails source code is here if anyone is interested.)