title: can't delete object due to foreign key constraint
body: <p>I'm trying to do a simple <code>user.destroy</code> but running into the following error:</p>
  
  <blockquote>
    <p>ERROR:  update or delete on table "users" violates foreign key constraint "fk_rails_5373344100" on table "identities"
    DETAIL:  Key (id)=(2) is still referenced from table "identities".</p>
  </blockquote>
  
  <p>Here is my migration for Identities</p>
  
  <pre><code>class CreateIdentities &lt; ActiveRecord::Migration
    def change
      create_table :identities do |t|
        t.references :user, index: true, foreign_key: true
        t.string :provider
        t.string :uid
  
        t.timestamps null: false
      end
    end
  end
  </code></pre>
  
  <p>Here is my user and identity model:</p>
  
  <pre><code>class Identity &lt; ActiveRecord::Base
    belongs_to :user
  
    validates_presence_of :uid, :provider
    validates_uniqueness_of :uid, :scope =&gt; :provider
  
    def self.find_for_oauth(auth)
      find_or_create_by(uid: auth.uid, provider: auth.provider)
    end
  end
  </code></pre>
  
  <p>and user:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    TEMP_EMAIL_PREFIX = 'ricky@writeit.com'
    TEMP_EMAIL_REGEX = /\ricky@writeit.com/
  
    # Include default devise modules. Others available are:
    # :lockable, :timeoutable
    devise :database_authenticatable, :registerable, :confirmable,
           :recoverable, :rememberable, :trackable, :validatable, :omniauthable
  
    validates_format_of :email, :without =&gt; TEMP_EMAIL_REGEX, on: :update
  ...
  
  end
  </code></pre>
  
  <p>I'm new to foreign keys and references, so I'm not sure at all how to fix this.</p>