Rails3与SQLite3 :: SQLException:没有这样的列HABTM

时间:2011-07-07 10:56:28

标签: ruby-on-rails-3 sqlite has-and-belongs-to-many

在Rails3中使用Sqlite3,我收到带有has_and_belongs_to_many情况的“ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:no such column”。从连接到Sqlite3的rails控制台,page.editors或page.admin_users

时出错

[[[编辑:由于连接表ID中的拼写错误而解决]]]

安装了宝石

rails 3.0.9

sqlite3 1.3.3 x86-mingw32

sqlite3-ruby

(win7 64bit开发机器)

page.rb - >行





> 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

admin_users.rb - >行



>  class AdminUser      
>       has_and_belongs_to_many :pages
>       scope :named, lambda {|first,last| where(:first_name =>
> first, :last_name => last)}
>       
>     end

迁移文件 - >发现错别字!

    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

rails console错误

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 )

感谢Heikki的帖子。我自己修好了,然后才回到这里(噢哦),但我很乐意接受答案。发布它,我会检查它,因为这是正确的。欢呼声。