{"record":{"id":"3373df549c047611","repo":"voormedia/rails-erd","slug":"active-record-was-not-loaded","errorCode":null,"errorMessage":"Active Record was not loaded.","messagePattern":"Active Record was not loaded\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/rails_erd/tasks.rake","lineNumber":64,"sourceCode":"\n    say \"Loading code in search of Active Record models...\"\n    begin\n      Rails.application.eager_load!\n\n      if Rails.application.respond_to?(:config) && !Rails.application.config.nil?\n        Rails.application.config.eager_load_namespaces.each(&:eager_load!) if Rails.application.config.respond_to?(:eager_load_namespaces)\n      end\n    rescue Exception => err\n      if Rake.application.options.trace\n        raise\n      else\n        trace = Rails.backtrace_cleaner.clean(err.backtrace)\n        error = ([\"Loading models failed!\\nError occurred while loading application: #{err} (#{err.class})\"] + trace).join(\"\\n    \")\n        raise error\n      end\n    end\n\n    raise \"Active Record was not loaded.\" unless defined? ActiveRecord\n  end\n\n  task :generate => [:options, :check_dependencies, :load_models] do\n    include ErdRakeHelper\n\n    say \"Generating Entity-Relationship Diagram for #{ActiveRecord::Base.descendants.length} models...\"\n\n    file = case RailsERD.options.generator\n    when :mermaid\n      require \"rails_erd/diagram/mermaid\"\n      RailsERD::Diagram::Mermaid.create\n    when :graphviz\n      require \"rails_erd/diagram/graphviz\"\n      RailsERD::Diagram::Graphviz.create\n    else\n      raise \"Unknown generator: #{RailsERD.options.generator}\"\n    end\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/voormedia/rails-erd/blob/dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165/lib/rails_erd/tasks.rake#L46-L82","documentation":"Error \"Active Record was not loaded.\" thrown in voormedia/rails-erd.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","solutions":["Run the task inside a Rails application so the `environment` task loads ActiveRecord: `bundle exec rake erd` from the Rails app root.","Ensure `activerecord` is in your Gemfile and required in config/application.rb (`require 'active_record/railtie'` or `require 'rails/all'`).","If you only need models without a full Rails app, establish the connection and load ActiveRecord yourself before invoking the rake task."],"exampleFix":"bundle exec rake erd  # run from the Rails application root, not a plain gem directory","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165","analyzedAt":"2026-08-23T02:52:18.679Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}