{"record":{"id":"5ac526c979cf571a","repo":"voormedia/rails-erd","slug":"no-entities-found-create-your-models-first","errorCode":null,"errorMessage":"No entities found; create your models first!","messagePattern":"No entities found; create your models first!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/rails_erd/diagram.rb","lineNumber":239,"sourceCode":"\n    def save\n      instance_eval(&callbacks[:save])\n    end\n\n    private\n\n    def callbacks\n      @callbacks ||= self.class.send(:callbacks)\n    end\n\n    def filtered_entities\n      @domain.entities.reject { |entity|\n        excluded_by_filter?(entity) or\n        !options.inheritance && entity.specialized? or\n        !options.polymorphism && entity.generalized? or\n        !options.disconnected && entity.disconnected?\n      }.compact.tap do |entities|\n        raise \"No entities found; create your models first!\" if entities.empty?\n      end\n    end\n\n    def filtered_relationships\n      @domain.relationships.reject { |relationship|\n        (!options.indirect && relationship.indirect?) ||\n          # Drop relationships to a model removed by :only/:exclude, otherwise the filtered-out\n          # model leaks back in: Graphviz skips such edges implicitly (it only draws an edge when\n          # both nodes exist) but Mermaid emits every relationship and renders any named entity.\n          excluded_by_filter?(relationship.source) ||\n          excluded_by_filter?(relationship.destination)\n      }\n    end\n\n    # Whether the entity was removed from the diagram by the :only or :exclude option.\n    # Used to filter both entities and the relationships that touch them.\n    #\n    def excluded_by_filter?(entity)","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/voormedia/rails-erd/blob/dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165/lib/rails_erd/diagram.rb#L221-L257","documentation":"Diagram#generate builds filtered_entities (diagram.rb:232-241): it rejects entities removed by the :only/:exclude filters, STI child entities while options.inheritance is false, polymorphic parents while options.polymorphism is false, and -- by default (disconnected: false) -- every entity with no relationships. If nothing survives the rejects, generation aborts with this RuntimeError. So either the app has no ActiveRecord models discoverable by RailsERD::Domain, or the combination of filters removed every entity.","triggerScenarios":"'rake erd' or RailsERD::Diagram.create in an app where ActiveRecord::Base.descendants is empty (fresh app, models never loaded, or running outside the Rails app); only: naming zero or only misspelled model names; exclude: covering every model; a domain consisting solely of STI children with inheritance disabled, or solely of disconnected entities with the default disconnected: false.","commonSituations":"Running erd on a brand-new app before the first scaffold; invoking the gem from a plain Ruby script or engine that never loads app/models; typos in ERD_ONLY / rake erd only= lists; lookup tables with no associations being silently excluded by the disconnected default; CI environments where eager loading is off.","solutions":["Confirm models are visible in the same context: bin/rails runner 'puts ActiveRecord::Base.descendants.map(&:name)' -- if empty, run from the app root / fix model loading","Check options.only and options.exclude (erd config file or rake erd only=Foo exclude=Bar) for typos or over-broad patterns","Re-include filtered categories: rake erd disconnected=true, or inheritance=true / polymorphism=true for STI- or polymorphic-only schemas","Create at least one model (rails g model ...) before generating the diagram"],"exampleFix":"# before -- filter names a model that does not exist\nRailsERD::Diagram::Graphviz.create(only: ['Usr'])\n# => RuntimeError: No entities found; create your models first!\n\n# after -- fix the name or drop the filter\nRailsERD::Diagram::Graphviz.create(only: ['User'])\nRailsERD::Diagram::Graphviz.create","handlingStrategy":"validation","validationCode":"entities = RailsERD::Domain.generate.entities\nvisible = entities.reject { |e| e.specialized? || e.generalized? || e.disconnected? }\nif visible.empty?\n  warn 'Nothing to draw - check :only/:exclude filters and that models are loaded'\nelse\n  RailsERD::Diagram::Graphviz.create\nend","typeGuard":null,"tryCatchPattern":"begin\n  RailsERD::Diagram::Graphviz.create\nrescue RuntimeError => e\n  raise unless e.message.include?('No entities found')\n  warn 'erd skipped: ' + e.message\nend","preventionTips":["Smoke-check ActiveRecord::Base.descendants before generating","Lint only/exclude lists against actual model names in a rake prerequisite","Remember disconnected entities are excluded by default - pass disconnected=true for association-less tables"],"tags":["ruby","rails-erd","activerecord","domain-model","only-exclude-filters","empty-result"],"backgroundTag":"no-models-found","analyzedSha":"dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165","analyzedAt":"2026-08-23T02:52:18.679Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}