Sreeraj Chundayil
Sreeraj Chundayil

Reputation: 5859

rake db:migrate is not creating user table

I have the following migrations

enter image description here

Problem is that rake db:migrate is not executing the first migration and no users table is created.

What could be the reason for this?

enter image description here

Upvotes: 1

Views: 1539

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

What could be the reason for this?

Main reason is probably that you've already ran the migration - or perhaps later migrations - and Rails therefore does not think it needs to run it.

A good way to see if this is the case is to open your db/schema.rb file:

enter image description here

You'll see the latest migration your schema is running. If this supersedes the one you're trying to invoke, it will not run.

--

Fixes

You could generate a new migration, and copy the code over:

$ rails g migration AddUsers2

You'd then add the following:

#db/migrate/_____.rb
class AddUsers2 < ActiveRecord::Migration
   def change
      create_table :users do |t| 
        t.string :name
        t.timestamps
      end
   end
end

Alternatively, you could wipe your DB and start again. This can be achieved using rake schema:load. THIS WILL WIPE ALL DATA AND START AGAIN

Upvotes: 2

Related Questions