Search code examples
ruby-on-railsrails-migrations

Create a Users model where previous Users model existed then dropped


I am working on a Rails application where the previous developer had created a Users model, then later dropped it in lieu of another solution. The migration files are still in the repository, but obviously the table doesn't exist. I am now trying to create a User authentication system to integrate a blog, but I am running into the issue of the previous migration and getting the following error message when trying rails g model User:

"Another migration is already named create_users..."

Is it possible there a way to create Users again?

Just to be extra clear. There is a create_users and later a drop_users migration.


Solution

  • 1. $ rails g model User --migration=false
    2. $ rails g migration create_users_again
    3. open create_users_again migration file (created in step 2), and define your table as:
    
      def change
        create_table :users do |t|
          t.email :string 
    
          t.timestamps
        end
    
        add_index :email
      end
    

    You can look your old create_users migration file for help.