Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4636

Ruby: add_reference in migration throws error: Table has no foreign key for

$
0
0

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?


Viewing all articles
Browse latest Browse all 4636

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>