 <p>You're setting a foreign key for <code>cards</code> table with the column <code>user_id</code>. But you haven't created a reference yet. Create a reference and then add foreign key to maintain referential integrity. Rollback and modify your migration with</p> <pre><code>1 class AddUserIdToCard &lt; ActiveRecord::Migration[5.0] 2 def change 3 add_reference :cards, :users, index:true 4 add_foreign_key :cards, :users 5 end 6 end </code></pre> <p>Line 3 will create, in the <code>cards</code> table, a reference to <code>id</code> in the <code>users</code> table (by creating a <code>user_id</code> column in <code>cards</code>).</p> <p>Line 4 will add a foreign key constraint to <code>user_id</code> at the database level.</p> <p>For more, read <a href="http://stackoverflow.com/questions/22815009/add-a-reference-column-migration-in-rails-4">Add a reference column migration in Rails 4</a></p>