0

I have a migration that creates a table, and I need to access the model for that table to create another table. The migration seems to not recognized that the original table has been created, so to make sure I put a debugger in my code and when I get to the model call, it says User(Table doesn't exist) even though in mysql I see it being created. Looks like migrations can't see the current state of the database, any ideas how to get around that?

Just to be more specific about my question: I'm trying to use Archivist to create archive of my current User table so I have

class ArchivedHeuristicReviewsTable < ActiveRecord::Migration
  def self.up
    create_table "users" do |t|
      t.string  "name"
      ...
    end
    debugger
    Archivist.update User
  end

  def self.down
    drop_table :users
    drop_table :archived_users
  end
end

the Archivist, doesn't create the archived_user table, so when I stopped at debugger and did User, I got User(Table doesn't exist).

I even tried Archivist call in a newer migration, so to make sure User creation is all done, but it still didn't recognize the user table.

Any ideas?

Matilda
  • 1,708
  • 3
  • 25
  • 33

1 Answers1

1

This should do the trick:

User.connection.schema_cache.clear!
User.reset_column_information
Matthias
  • 4,355
  • 2
  • 25
  • 34