Search code examples
ruby-on-railsrails-migrations

undefined local variable or method `correspondent_loans' for #<CreateCorrespondentLoans


I am using rails 4 & ruby 2.0.0.

when I hit rake db:migrate I get the error. It points to the add_index line having an issue.

 ==  CreateCorrespondentLoans: migrating ======================================
-- create_table(:correspondent_loans)
-> 0.0036s
-- correspondent_loans()
rake aborted!
 StandardError: An error has occurred, this and all later migrations canceled:

 undefined local variable or method `correspondent_loans' for #<CreateCorrespondentLoans:

Here's the code

    class CreateCorrespondentLoans < ActiveRecord::Migration
 def change
 create_table :correspondent_loans do |t|
  t.string :correspondent
  t.date :purchase_date
  t.decimal :loan_amount, precision: 15, scale: 2
  t.string :curr_status
  t.string :instrument_name
  t.string :loan_id, null: false

  t.timestamps
end

add_index correspondent_loans, loan_id, name: "index_correspondent_loans_loan_id", unique: true, using: :btree
  end
end

Solution

  • class CreateCorrespondentLoans < ActiveRecord::Migration
        def change
            create_table :correspondent_loans do |t|
                t.string :correspondent
                t.date :purchase_date
                t.decimal :loan_amount, precision: 15, scale: 2
                t.string :curr_status
                t.string :instrument_name
                t.string :loan_id, null: false
                t.timestamps
        end
        add_index :correspondent_loans, :loan_id, name: "index_correspondent_loans_loan_id", unique: true, using: :btree
        end
    end
    

    correspondent_loans and load_id should be a symbol.