English 中文(简体)
rails 3测试错误:Mysql2::错误:未知列
原标题:rails 3 test error:Mysql2::Error: Unknown column

伙计们,当我按照http://guides.rubyonrails.org/testing.html,上面写着:

test_the_truth(ClassroomTypeTest): ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column type in field list : INSERT INTO classroom_types (type, memo, created_at, updated_at, id) VALUES ( MyString , MyString , 2011-05-31 08:40:54 , 2011-05-31 08:40:54 , 980190962)

I am confused, I do not have a column in my classroom_types table,why will it appear such an error? Can anyone help me? Many Thanks!

以下是我的模型和关系:

ClassroomType型号:

class ClassroomType < ActiveRecord::Base
  has_many :classrooms
end

课堂模式:

class Classroom < ActiveRecord::Base
   belongs_to :classroom_type
   belongs_to :teaching_building
end

教学楼模型:

class TeachingBuilding < ActiveRecord::Base
  has_many :classrooms
end

以下是相应的表格:

教室:

  • id
  • classroom_no
  • classroom_name
  • classroom_type_id
  • teaching_building_id

教室类型(_T):

  • id
  • name
  • memo

教学_建筑:

  • id
  • t_no
  • name
问题回答

我想问题出在您的列命名上。当rails进行多态关联时,它会使用id联接表,并从xxx_type列中选择联接的表。我可以想象,如果您在数据库名称和列名中将“type”替换为(例如)“kind”,您的问题就会消失。

Samuel

I had encountered a similar problem but solved here s how

  1. go to mysql localserver
  2. then change the mysql column name correspoding to model having belongs_to
  3. Use "ALTER TABLE tablename CHANGE oldname newname VARCHAR (10) ;"
  4. This is because rails creates default as user_id

我认为问题是列命名,请检查数据库表的列名及其类型,并根据错误消息进行设置





相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签