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
- 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.
- 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.
- 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.
- 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
- In --skip-active-record apps, add the generators block (config.generators { |g| g.orm :mongoid }) before running any devise generators.
- Put the ORM gem above devise in the Gemfile so it loads first, and verify with rails runner 'puts Rails.application.config.generators.options[:rails][:orm]'.
- Re-run rails generate devise:install after fixing config/application.rb — the check happens per-generator-run, no migration cleanup needed.
- Stop spring/bootsnap-cached environments after config changes so the generator reads fresh settings.
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
- Could not find devise mapping for path #{request.fullpath.in
- :route should be true, a Symbol or a Hash
- #{name}
- "Devise doesn't know how to sanitize parameters for '#{actio
- Mapping omniauth_callbacks on a resource that is not omniaut
AI-assisted analysis of heartcombo/devise@372b295fe6 (2026-08-21).
Data as JSON: /api/errors/17dfee3789130b64.
Report an issue: GitHub.