heartcombo/devise · error · Devise::Generators::MissingORMError

An ORM must be set to install Devise in your application. B

Error message

An ORM must be set to install Devise in your application.

Be sure to have an ORM like Active Record or Mongoid loaded in your
app or configure your own at `config/application.rb`.

  config.generators do |g|
    g.orm :your_orm_gem
  end

What it means

The devise:install generator (rails generate devise:install) needs an ORM to later create models and migrations, and Rails feeds the configured ORM into the generator through the required orm class_option (set from config.generators, g.orm). When no ORM is configured — typically an app generated with --skip-active-record where no replacement like Mongoid was wired into generators — copy_initializer raises MissingORMError (a Thor::Error) telling you to set g.orm in config/application.rb. It is a setup-time guard, not a runtime failure.

Source

Thrown at lib/generators/devise/install_generator.rb:18

# frozen_string_literal: true

require 'rails/generators/base'
require 'securerandom'

module Devise
  module Generators
    MissingORMError = Class.new(Thor::Error)

    class InstallGenerator < Rails::Generators::Base
      source_root File.expand_path("../../templates", __FILE__)

      desc "Creates a Devise initializer and copy locale files to your application."
      class_option :orm, required: true

      def copy_initializer
        unless options[:orm]
          raise MissingORMError, <<-ERROR.strip_heredoc
          An ORM must be set to install Devise in your application.

          Be sure to have an ORM like Active Record or Mongoid loaded in your
          app or configure your own at `config/application.rb`.

            config.generators do |g|
              g.orm :your_orm_gem
            end
          ERROR
        end

        template "devise.rb", "config/initializers/devise.rb"
      end

      def copy_locale
        copy_file "../../../config/locales/en.yml", "config/locales/devise.en.yml"
      end

View on GitHub (pinned to 372b295fe6)

Solutions

  1. If you intend to use Mongoid: add gem "mongoid" to the Gemfile, bundle, and add to config/application.rb inside the Application class: config.generators do |g| g.orm :mongoid end — then re-run rails generate devise:install.
  2. If you want Active Record after all: ensure railties/active_record are not skipped (config.database.yml present, no --skip-active-record) and re-run the generator.
  3. For any other ORM adapter, register it the same way via config.generators do |g| g.orm :your_orm_gem end per the adapter's README, then re-run.
  4. Restart any spring/bootsnap-cached processes after editing config/application.rb so the generator sees the new setting.

Example fix

# before (config/application.rb, app generated with --skip-active-record)
module MyApi
  class Application < Rails::Application
    # no generators config -> devise:install raises MissingORMError
  end
end

# after (Gemfile)
gem "mongoid", "~> 8.0"

# config/application.rb
module MyApi
  class Application < Rails::Application
    config.generators do |g|
      g.orm :mongoid
    end
  end
end

# then re-run
# rails generate devise:install
Defensive patterns

Strategy: validation

Validate before calling

# Check ORM generator config before invoking the generator:
def orm_configured?
  Rails.application.config.generators.options.dig(:rails, :orm).present?
end

raise "Configure config.generators { |g| g.orm :mongoid } first" unless orm_configured?
# safe to run: rails generate devise:install

Type guard

def orm_configured?
  Rails.application.config.generators.options.dig(:rails, :orm).present?
end

Prevention

When it happens

Trigger: Running rails generate devise:install in a Rails app created with --skip-active-record before adding config.generators { |g| g.orm :mongoid }; using Devise with MongoMapper/DataMapper-era or custom ORMs without generator config; the ORM gem is in the Gemfile but config/application.rb was never told about it, so Rails' generator framework passes a nil orm option.

Common situations: Adding Devise to a Mongoid app (most common non-AR pairing) and forgetting the generators block; API-only or minimal apps with Active Record stripped; CI scaffolding scripts that run devise:install before application.rb is fully set up.

Related errors


AI-assisted analysis of heartcombo/devise@372b295fe6 (2026-08-21). Data as JSON: /api/errors/17dfee3789130b64. Report an issue: GitHub.