title: Adding Devise to Rails app NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection
body: <p><strong>When adding Devise to an application with an existing User making the mistake of forgetting to run the installer, it seems to bork the application, database can't migrate and devise routes aren't available when running <code>rails routes</code>; NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection</strong></p>
  <h2>Environment</h2>
  <p>Ruby <strong>2.6.3</strong>
  Rails <strong>6.1.3</strong>
  Devise <strong>4.7.3</strong></p>
  <h2>example app</h2>
  <p><a href="https://github.com/jasonfb/DEVISE002" rel="nofollow noreferrer">https://github.com/jasonfb/DEVISE002</a></p>
  <h2>steps to reproduce</h2>
  <p>1- <code>rails new TestApp</code></p>
  <p>2- <code>cd TestApp/</code></p>
  <p>3- add <code>gem devise</code> to Gemfile &amp; bundle install</p>
  <p>4- Now,  create a User model (as if you had a User model existing before you added Devise to your app) , do this with <code>rails generate model User</code></p>
  <p>5- now <em>make the mistake</em> of forgetting to run the devise installer itself</p>
  <p>6- now run the devise generator on your already-created User with <code>rails generate devise User</code></p>
  <p>7- run <code>rails db:migrate</code>. this migration will FAIL, throwing the following error:</p>
  <p>(does not make sense, because devise is installed into the gem file)</p>
  <pre><code>jason@MBP ~/Work/_LEARNING/Turbo-Rails/DEVISE002 (master) $ rails db:migrate
  rails aborted!
  NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection):Class
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/app/models/user.rb:4:in `&lt;class:User&gt;'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/app/models/user.rb:1:in `&lt;main&gt;'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/config/routes.rb:2:in `block in &lt;main&gt;'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/config/routes.rb:1:in `&lt;main&gt;'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/config/environment.rb:5:in `&lt;main&gt;'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/rails:5:in `&lt;top (required)&gt;'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/spring:10:in `block in &lt;top (required)&gt;'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/spring:7:in `tap'
  /Users/jason/Work/_LEARNING/Turbo-Rails/DEVISE002/bin/spring:7:in `&lt;top (required)&gt;'
  Tasks: TOP =&gt; db:migrate =&gt; db:load_config =&gt; environment
  (See full trace by running task with --trace)
  
  </code></pre>
  <p>Symptom 1: The database doesn't migrate and <code>rails db:migrate</code> crashes with the above error.</p>
  <p>Symptom 2: on one of my test apps where I made this mistake, the devise routes didn't seem to load although <code>devise_for :users</code> was in the routes.rb file.</p>