title: Rails3 with SQLite3::SQLException: no such column HABTM
body: <p>Using Sqlite3 with Rails3 and I receive "ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column" with a has_and_belongs_to_many situation.  From rails console connected to Sqlite3, errors when page.editors or page.admin_users</p>
  
  <p>[[[EDIT: Solved because of typos in the join table id's]]]</p>
  
  <p>gems installed</p>
  
  <p>rails 3.0.9</p>
  
  <p>sqlite3 1.3.3 x86-mingw32</p>
  
  <p>sqlite3-ruby </p>
  
  <p>(win7 64bit dev machine)</p>
  
  <p>page.rb --> OK</p>
  
  <pre>
  
  
  
  
  > class Page      
  >        belongs_to :subject
  >        has_many :sections
  >        has_and_belongs_to_many :editors, :class_name => "AdminUser"
  >        #has_and_belongs_to_many :admin_users
  >        
  >        end
  
  </pre>
  
  <p>admin_users.rb --> OK</p>
  
  <pre>
  
  
  >  class AdminUser      
  >       has_and_belongs_to_many :pages
  >       scope :named, lambda {|first,last| where(:first_name =>
  > first, :last_name => last)}
  >       
  >     end
  
  </pre>
  
  <p>migration file  --> Spot the Typos!  </p>
  
  <pre>
      class CreateAdminUsersPagesJoin  false do |t|
            t.integer :admin_users_id, :foreign_key => true  # Should be admin_user_id
            t.integer :page_id, :foreign_key => true
          end
          add_index :admin_users_pages, [:admin_users_id, :page_id]  # Again admin_user_id
        end
  
        def self.down  
          drop_table :admin_users_pages
        end
  
      end
  </pre>
  
  <p>rails console errors</p>
  
  <pre>
  irb(main):004:0> page.admin_users
  ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: admin_users_pages.admin_user_id: SELECT * FROM "admin_users
  " INNER JOIN "admin_users_pages" ON "admin_users".id = "admin_users_pages".admin_user_id WHERE ("admin_users_pages".page_id = 2 )
  </pre>
  
  <p>Thanks to Heikki for the posts.  I fixed it myself before looking back here only now (d'oh) but I'll happily accept the answer.  Post it and I'll check it since that was correct.  Cheers.</p>