title: Rails Tutorial: SQLite3::ConstraintException: UNIQUE constraint failed: users.email
body: <p>I'm following along with the rails tutorial. I'm on ch. 6 and I'm getting a strange error with SQLite3 (for the record, I'm using sqlite version 1.3.10 and the tutorial uses 1.3.9)</p>
  
  <p>I don't get an error when I run rake db:migrate, but when I run the migration for the test environment, here's what I get:</p>
  
  <pre><code>$ bundle exec rake test:models
  
  rake aborted!
  ActiveRecord::PendingMigrationError:
  
  Migrations are pending. To resolve this issue, run:
  
      bin/rake db:migrate RAILS_ENV=test
  
  sample_app/test/test_helper.rb:3:in `&lt;top (required)&gt;'
  sample_app/test/models/user_test.rb:1:in `require'
  sample_app/test/models/user_test.rb:1:in `&lt;top (required)&gt;'
  Tasks: TOP =&gt; test:models
  (See full trace by running task with --trace)
  
  
  $ bundle exec rake db:migrate RAILS_ENV=test
  
  == 20150628011937 AddIndexToUsersEmail: migrating ===========================
  ==
      -- add_index(:users, :email, {:unique=&gt;true})
  rake aborted!
  StandardError: An error has occurred, this and all later migrations canceled:
  
  
  SQLite3::ConstraintException: UNIQUE constraint failed: users.email: CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")sample_app/db/migrate/20150628011937_add_index_to_users_email.rb:3:in `change'
  C:in `migrate'
  ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constrain
  t failed: users.email: CREATE UNIQUE INDEX "index_users_on_email" ON "users"
  ("email")
  sample_app/db/migrate/20150628011937_add_index_to_users_email.rb:3:in `change'
  C:in `migrate'
  SQLite3::ConstraintException: UNIQUE constraint failed: users.email
  sample_app/db/migrate/20150628011937_add_index_to_users_email.rb:3:in `change'
  C:in `migrate'
  Tasks: TOP =&gt; db:migrate
  (See full trace by running task with --trace)
  </code></pre>
  
  <p>Here is my user.rb model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    before_save { self.email = email.downcase }
    validates :name, presence: true, length: { maximum: 50 }
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    validates :email, presence: true, length: { maximum: 255 },
                      format: { with: VALID_EMAIL_REGEX },
                      uniqueness: { case_sensitive: false }
  end
  </code></pre>
  
  <p>Here is my most recent migration </p>
  
  <pre><code>  class AddIndexToUsersEmail &lt; ActiveRecord::Migration
      def change
        add_index :users, :email, unique: true
      end
    end
  </code></pre>
  
  <p>I can post any other files if those are relevant. Thanks in advance for the help!</p>