I'm new to Ruby on Rails and I'm following the https://www.railstutorial.org/book/ guide to understand a bit more about it. I'm stuck at 6.3.3, where it tells to create a secure password. The previous migration seemed to have worked (to create a unique index and to create the secure password column). After that when i try to run:
rake test
it says that the test was aborted and that i should run:
rake db:migrate RAILS_ENV=test
but when i do run the command above it returns this:
c:\Sites\sample_app>rake db:migrate RAILS_ENV=test
DL is deprecated, please use Fiddle
== 20141226095217 AddIndexToUsersEmail: migrating =============================
-- add_index(:users, :email, {:unique=>true}) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: indexed columns are not unique: CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")c:/Si tes/sample_app/db/migrate/20141226095217_add_index_to_users_email.rb:3:in `change' C:in `migrate' Tasks: TOP => db:migrate (See full trace by running task with --trace)
I don't understand why this is happening. My DB is empty.
As requested, the migrations files:
20141226095217_add_index_to_users_email.rb
class AddIndexToUsersEmail < ActiveRecord::Migration
def change
add_index :users, :email, unique: true
end
end
20141226095746_add_password_digest_to_users.rb
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
db/migrate/20141226095217_add_index_to_users_email.rband previos migration file too.unique: truefromAddIndexToUsersEmailmigration.db/scheme.rbfor your database schema before run generate migration.