Rails, Uninitialized constant after rake db:migrate
<p>I'm following the book: "Rails, Angular, Postgres and Bootstrap". At some point, the author wrote a new migration, with this code:</p>

<pre><code>class AddAddresses &lt; ActiveRecord::Migration
  def change
    create_table :states do |t|
      t.string :code, size: 2, null: false
      t.string :name,          null: false
    end

    create_table :addresses do |t|
      t.string     :street,                    null: false
      t.string     :city,                      null: false
      t.references :state,                     null: false
      t.string     :zipcode,                   null: false
    end

    create_table :customers_billing_addresses do |t|
      t.references :customer, null: false
      t.references :address,  null: false
    end

    create_table :customers_shipping_addresses do |t|
      t.references :customer, null: false
      t.references :address,  null: false
      t.boolean :primary, null: false, default: false
    end
  end
end
</code></pre>

<p>Here is what I did:</p>

<ol>
<li><p><code>rails g migration add-addresses</code></p></li>
<li><p>Copied and pasted the code above in the generated migration-file</p></li>
<li><p><code>rake db:migrate</code></p></li>
</ol>

<p>This happens:</p>

<pre><code>== 20161211174928 AddAddresses: migrating =====================================
-- create_table(:states)
   -&gt; 0.0140s
-- create_table(:addresses)
   -&gt; 0.0129s
-- create_table(:customers_billing_addresses)
   -&gt; 0.0115s
-- create_table(:customers_shipping_addresses)
   -&gt; 0.0142s
== 20161211174928 AddAddresses: migrated (0.0529s) ============================
</code></pre>

<ol start="4">
<li><code>rails c</code></li>
<li><p><code>State.last</code> causes this:</p>

<p><code>NameError: uninitialized constant State</code></p></li>
<li><p>I checked, whether 'State' was around: </p>

<pre><code>ActiveRecord::Base.connection.tables.map do |model|  
  model.capitalize.singularize.camelize
end
</code></pre></li>
</ol>

<p>leads to:</p>

<pre><code>["SchemaMigration", "ArInternalMetadatum", "User", "Customer", "State", "Address", "CustomersBillingAddress", "CustomersShippingAddress"]
</code></pre>

<p>Since 'State' is clearly there, I'm clueless what the problem is. Any suggestions?</p>

<p>PS: I already tried this, but the problem remains:</p>

<pre><code>rake db:drop:all
rake db:create:all
rake db:migrate
</code></pre>