greenif
greenif

Reputation: 1093

rails 5 migration uninitialized constant

I have project on rails 4.2 with bunch of migrations. And on rails 4.2 everything works perfectly.

Now I created a new project on rails 5 and copied all my migrations from 4.2 project to new project.

When I try to run rails db:migrate, first 30 migrations run normal, then on 31, very simple migration, I have error:

uninitialized constant AddFactorToCurrencies::Currency

The file name is db/migrate/20160715140911_add_factor_to_currencies.rb

class AddFactorToCurrencies < ActiveRecord::Migration[5.0]
  def up
    add_column :currencies, :factor, :decimal, precision:18, scale:2, default:0, null: false
    Currency.all.each do |c|
      c.factor = 0
      c.save
    end
  end

  def down
    remove_column :currencies, :factor
  end
end

Help me please.

Upvotes: 0

Views: 996

Answers (1)

nikkypx
nikkypx

Reputation: 2005

It does not recognize Currency in that file. Create a currency model.

Upvotes: 1

Related Questions