ruby on rails - Rake db:migrate duplicate with Devise -
so i'm having issues migrations in rails.. have 2 migrations 1 add users table , 1 add devise users...
now im getting error when try run
rake db:migrate
activerecord::statementinvalid: sqlite3::sqlexception: duplicate column name: email: alter table "users" add "email" varchar default '' not null
which tells me both migrations trying add column email users table..
user table create migration
class createusers < activerecord::migration def change create_table :users |t| t.string :name t.string :email t.string :password_digest t.timestamps null: false end end end
devise added users migration
class adddevisetousers < activerecord::migration def self.up change_table(:users) |t| ## database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" ## recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## rememberable t.datetime :remember_created_at ## trackable t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip t.string :last_sign_in_ip ## confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # if using reconfirmable ## lockable # t.integer :failed_attempts, default: 0, null: false # if lock strategy :failed_attempts # t.string :unlock_token # if unlock strategy :email or :both # t.datetime :locked_at # uncomment below if timestamps not included in original model. # t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true # add_index :users, :confirmation_token, unique: true # add_index :users, :unlock_token, unique: true end def self.down # default, don't want make assumption how roll migration when # model existed. please edit below fields remove in migration. raise activerecord::irreversiblemigration end end
im assuming the
add_index :users, :email, unique: true
line in 2nd migration causing issue... im curious... line relevant devise? can't find relating in documentation... if delete 2 lines have effect on way devise runs??
you trying create column email
twice: in own migration , in devise. also, don't need password_digest
column. second time got error because column exists.
my advice rollback on version before creating users (rake db:rollback version=timestamp_from_migration_filename), remove email , password_digest createusers , try again migrations.
Comments
Post a Comment