rails generate paperclip_database:migration getting protected method `migration_file_name' error

Quick fix (put this in application.rb or similar in order to run the rails generate paperclip_databasee:migration command):

module PaperclipDatabase
  module Generators
    class MigrationGenerator
      public :migration_file_name
    end
  end
end

There are two errors causing this error, one in paperclip and one in paperclip_database. Not sure what changes to Rails 4 caused this, but the issue is fixed in this commit in paperclip, which probably needs to be mirrored in paperclip_database. (Even if I point to the github repo for paperclip, I still get the error due to protected being specified on paperclip_database as well.

The error only appears to affect the generator.

If you'd rather not have a temporary monkey patch, you can write the migration by hand:

Example (for a User with an avatar attachment):

class CreateUserAvatar < ActiveRecord::Migration
  def self.up
    create_table :avatars do |t|
      t.integer    :user_id
      t.string     :style
      t.binary     :file_contents
    end
  end

  def self.down
    drop_table :avatars
  end
end

foreigner foreign_key on a different column in source and target table.

In the foreigner gem, you can specify the foreign_key column on the source table by using the column option.

class Cats < ActiveRecord::Migration
  def change
    create_table :cats do |t|
      t.integer :color_id
      t.integer :second_color_id

      t.timestamps
    end
    add_foreign_key :cats, :colors, column: :second_color_id
  end
end

But what about the target table? This can be accomplished using the primary_key option.

class Dogs < ActiveRecord::Migration
  def change
    create_table :dogs do |t|
      t.integer :color_id
      t.integer :breed_name

      t.timestamps
    end
    add_foreign_key :dogs, :breed, column: :breed_name, primary_key: :name
  end
end

Of course, the model has to change as well:

class Dog < ActiveRecord::Base
  belongs_to :breed, primary_key: :name
end