title: How do I create a Rails migration that updates a foreign key with an on-delete cascade constraint?
body: <p>I’m using Rails 4.2.3 and a PostgreSQL database.  I want to write a migration to update one of my foreign keys to have an on-delete cascade constraint, so I created the following:</p>
  
  <pre><code>class UpdateForeignKeyAddOnDeleteConstraint &lt; ActiveRecord::Migration
    def change
      remove_foreign_key :my_object_times, :my_objects
      add_foreign_key :my_object_times, :my_objects, on_delete: cascade
    end
  end
  </code></pre>
  
  <p>but when I run the migration I get the error below:</p>
  
  <pre><code>$ rake db:migrate
  == 20160525203028 UpdateForeignKeyAddOnDeleteConstraint: migrating ============
  -- remove_foreign_key(:my_object_times, :my_objects)
     -&gt; 0.0454s
  -- cascade()
  rake aborted!
  StandardError: An error has occurred, this and all later migrations canceled:
  
  undefined local variable or method `cascade' for #&lt;UpdateForeignKeyAddOnDeleteConstraint:0x007f82f2c71998&gt;
  /Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:664:in `block in method_missing'
  /Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:634:in `block in say_with_time'
  /Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:634:in `say_with_time'
  /Users/davea/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:654:in `method_missing'
  </code></pre>
  
  <p>How am I supposed to write my migration to update the foreign key?</p>