Name is already used or reserved by Ruby on Rails?

Adding two other possible reasons people might get this error.

Firstly you've been changing names and the old name is still around as it's a caching issue.

Secondly, it could be a naming conflict with a gem you have installed. So the gem is already using the name you want to use.

CASE I:: Cache issue

I got below error::

The name 'Activityflow' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

While running rails g if you see below messages in initial lines. It could be cache issue:

warning: previous definition of CALLBACK_CAMPAIGN_NAME was here
Running via Spring preloader in process 98806
      invoke  active_record

Solution is kill spring and it will freeup cache.

Find process id of spring

$ ps -ef | grep spring
501 82388 82384   0  2:21PM ??        66:34.87 spring app    | insurance | started 16 hours ago | development mode      
501 82384     1   0  2:21PM ttys005    0:00.84 spring server | insurance | started 16 hours ago   

Kill process Eg: 82384 in above case

$ kill -9 82384

Then when you run rails g command again; Spring will run/start with fresh contents and model creation succeed.

Running via Spring preloader in process 99237
  invoke  active_record
  create    db/migrate/20200518021818_create_activityflows.rb
  create    app/models/activityflow.rb
  invoke    rspec
  create      spec/models/activityflow_spec.rb

CASE II:: Module Issue

I got below error::

The name 'Workflow' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

The issue was I was using gem gem 'workflow', '~> 2.0.2' which creates modules names Workflow and does not allow to generate model named Workflow.

So, be careful when you use any gem and is module name in any gem gets matched with model name.

Simple way to check if module name exist is::
$ bin/rails c
[4] pry(main)> Workflow
=> Workflow
[5] pry(main)> Workflow.class
=> Module

You may not create a model with the same name as the Application because it will create conflicting names. When you create an application i.e. rails new Education it will create a module named Education as follows

module Education
  class Application < Rails::Application
  #....
  end
end

This named module is then called in files such as config.ru, routes.rb and environment.rb and many more. So if you were able to create a model class by the same name it would create ambiguity as to whether you were calling the Model or the Module.