Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method `column' for Foreigner::ConnectionAdapters::ForeignKeyDefinition

I'm getting the following when I try to run a migration:

NoMethodError: undefined method `column' for #<Foreigner::ConnectionAdapters::ForeignKeyDefinition:0x007fa020938740>

Here's the migration code:

class CreateAdvertisement < ActiveRecord::Migration
  def change
    create_table :advertisement do |t|
      t.integer :issue_id, null: false
      t.string :client_name, null: false
      t.decimal :size, null: false
      t.decimal :price, null: false
      t.decimal :commission_amount, null: false
      t.string :first_payment, null: false
      t.string :second_payment, null: false

      t.timestamps null: false
      t.foreign_key :issue
    end
  end
end

I have Foreigner 1.6.1 installed, Rails 4.2.0. Any ideas?

like image 538
Jason Swett Avatar asked Oct 30 '14 18:10

Jason Swett


2 Answers

You, or one of your gems use the 'foreigner' gem, which is deprecated with rails 4.2.0

You should update it or remove this dependency. Maybe someone already did it, for example i use 'mailboxer' gem, and 'github.com/div' already forked the project to create a branch, so i changed my Gemfile :

gem 'mailboxer', :git => 'git://github.com/div/mailboxer.git', :branch => 'rails42-foreigner'
like image 186
Nicolas Maloeuvre Avatar answered Oct 13 '22 00:10

Nicolas Maloeuvre


You don't need foreigner with Rails 4.2, as it already has foreign-key support built-in. The syntax is very similar (although not identical) to foreigner.

See: http://edgeguides.rubyonrails.org/4_2_release_notes.html#foreign-key-support

like image 27
elsurudo Avatar answered Oct 13 '22 02:10

elsurudo