Project

General

Profile

Actions

Refactor #14094

closed

Replace DB migration foreign_keys calls with foreign_key_exists?

Added by Dominic Cleal over 8 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
DB migrations
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

In Rail 4.2 and higher, where native foreign key support replaces Foreigner, the "foreign_keys" call inside a DB migration should be avoided as it will throw an exception on databases (SQLite) that don't support FKs.

https://github.com/rails/rails/blob/6298ac705da92cc793cbf40dd91484d34e01d255/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L671

In Foreigner, it returned [] on SQLite. In #13244 (Rails 4.2) I'll add a compatibility layer with a deprecation warning, but our migrations that use this to check whether a key exists should just use the foreign_key_exists? method for better compatibility.


Related issues 1 (0 open1 closed)

Blocks Foreman - Feature #13244: Upgrade Ruby on Rails to 4.2ClosedDominic Cleal01/15/2016Actions
Actions

Also available in: Atom PDF