0

I have been trying to use devise to make an authentication system for a blog that I am programming.When I try to view the blog, it says (Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue.), and when I run the command, it fails and renders this message:

Moussas-MacBook-Pro:theBlog moussasarr$ bin/rake db:migrate RAILS_ENV=development
== 20141031151735 SorceryCore: migrating ======================================
-- create_table(:authors)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "authors" already exists: CREATE TABLE "authors" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "username" varchar(255) NOT NULL, "email" varchar(255) NOT NULL, "crypted_password" varchar(255) NOT NULL, "salt" varchar(255) NOT NULL, "created_at" datetime, "updated_at" datetime) /Users/moussasarr/.rvm/gems/ruby-2.0.0-p576@railstutorial_rails_4_0/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'

. I did migrate the authors table in the past but I had to restart from an earlier point as it was not working out. How can I delete the SorceryCore migration to make a new one ?

Here is the migration table:

class SorceryCore < ActiveRecord::Migration
    def change
     create_table :authors do |t|
      t.string :username,         :null => false
      t.string :email,            :null => false
      t.string :crypted_password, :null => false
      t.string :salt,             :null => false
      t.timestamps
      end
      add_index :authors, :email, unique: true
      end
      end

I really want to get this table out of the database and push in a new table. Thanks a lot for your help ! This is the original problem that made me restart at an earlier level and made me lose so much time.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
codigomonstruo
  • 1,081
  • 1
  • 11
  • 45
  • You can `rake db:migrate:reset` if you don't care about the data locally. You'll have to `rake db:seed` after, or just put new stuff in since that will delete everything. – jeremywoertink Oct 31 '14 at 15:50
  • Thanks jeremy for your answer! Will that delete the structure of some models that I perfected through migrations ? Will I have to redo all migrations ? – codigomonstruo Oct 31 '14 at 15:55
  • the `rake db:migrate:reset` command will just drop the entire database, then re-run all migrations from the very beginning. It is just a quick way to resync all your migrations if they're out like you have. No need to change models or anything (usually). – jeremywoertink Oct 31 '14 at 15:57
  • It s not letting me run rake db:migrate:reset. It says : – codigomonstruo Oct 31 '14 at 16:07

1 Answers1

0

You can do db:migrate:down VERSION=your_migration_version to drop the table from the database, then delete the migration file and then run the migrations that devise needs for your authentication.

However, make sure that you don't need the authors table in any migrations until the devise one as it won't exist and can be a potentially big problem with your codebase and everything.

sebkkom
  • 1,426
  • 17
  • 31