I have this migration:
class AddNotificationSettingToHistoricals < ActiveRecord::Migration[6.1] def change unless foreign_key_exists?(:sms_historicals, column: :notification_setting_id) add_reference :sms_historicals, :notification_setting, foreign_key: true end unless foreign_key_exists?(:email_historicals, column: :notification_setting_id) add_reference :email_historicals, :notification_setting, foreign_key: true end endend
but when I run it, it throws this error:
Table 'email_historicals' has no foreign key for notification_settings
What I don't understand is that I have these in the migration:
unless foreign_key_exists?(:email_historicals, column: :notification_setting_id)
Which does throw false.. so yes there is no foreign key, that's why I'm trying to add it.. Yea I'm not sure why its doing this.. Any ideas?