voormedia/rails-erd · error

Active Record was not loaded.

Error message

Active Record was not loaded.

What it means

Error "Active Record was not loaded." thrown in voormedia/rails-erd.

Source

Thrown at lib/rails_erd/tasks.rake:64

    say "Loading code in search of Active Record models..."
    begin
      Rails.application.eager_load!

      if Rails.application.respond_to?(:config) && !Rails.application.config.nil?
        Rails.application.config.eager_load_namespaces.each(&:eager_load!) if Rails.application.config.respond_to?(:eager_load_namespaces)
      end
    rescue Exception => err
      if Rake.application.options.trace
        raise
      else
        trace = Rails.backtrace_cleaner.clean(err.backtrace)
        error = (["Loading models failed!\nError occurred while loading application: #{err} (#{err.class})"] + trace).join("\n    ")
        raise error
      end
    end

    raise "Active Record was not loaded." unless defined? ActiveRecord
  end

  task :generate => [:options, :check_dependencies, :load_models] do
    include ErdRakeHelper

    say "Generating Entity-Relationship Diagram for #{ActiveRecord::Base.descendants.length} models..."

    file = case RailsERD.options.generator
    when :mermaid
      require "rails_erd/diagram/mermaid"
      RailsERD::Diagram::Mermaid.create
    when :graphviz
      require "rails_erd/diagram/graphviz"
      RailsERD::Diagram::Graphviz.create
    else
      raise "Unknown generator: #{RailsERD.options.generator}"
    end

View on GitHub (pinned to dae6e52018)

Solutions

  1. Run the task inside a Rails application so the `environment` task loads ActiveRecord: `bundle exec rake erd` from the Rails app root.
  2. Ensure `activerecord` is in your Gemfile and required in config/application.rb (`require 'active_record/railtie'` or `require 'rails/all'`).
  3. If you only need models without a full Rails app, establish the connection and load ActiveRecord yourself before invoking the rake task.

Example fix

bundle exec rake erd  # run from the Rails application root, not a plain gem directory

When it happens

Trigger: Raised at the end of the erd:load_models rake task, after eager-loading the application, when ActiveRecord is still not defined, e.g. running `rake erd` in an app that does not use Active Record or outside a Rails application.

Common situations: See trigger scenarios.


AI-assisted analysis of voormedia/rails-erd@dae6e52018 (2026-08-23). Data as JSON: /api/errors/3373df549c047611. Report an issue: GitHub.