I'm maintaining an old system that uses Rails 4.2 and for an unknown reason the references are created this way:
t.references :credit_card, null: false
t.references :car, null: false
t.references :profile, null: false
This allows me to create registers for this model with invalid credit_card ids, for example.
Foreign key isn't validated.
Generating index migration didn't turn them into fk's and didn't validate them at all:
class AddIndexToRentals < ActiveRecord::Migration
add_index :rentals, :credit_card_id
add_index :rentals, :car_id
add_index :rentals, :profile_id
How can I make those fields foreign keys and accept only existent ids?