问题描述
我重命名的表的3列,突然我所有的单元和功能测试抛出同样的错误,他们无法找到表与旧的列名。即使是测试什么都没有做的表我修改掷模型,同样的错误:
I renamed 3 columns of a table and suddenly ALL of my unit and functional tests throw the same error, that they cannot find the table with the old column names. Even the tests for the models that have nothing to do with the table I modified throw that same error:
例如:
54) Error:
test_should_show_user(UsersControllerTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: table answers has no column named id_user: INSERT INTO "a
nswers" ("id_user", "id_survey", "id_question", "answer", "created_at", "updated_at", "id") VALUES ('MyString',
1, 1, 'MyText', '2012-06-16 17:45:56', '2012-06-16 17:45:56', 980190962)
这是我做的事在我的迁移更改表:
this is what I did in my migration to alter the table:
class EditAnswersTable < ActiveRecord::Migration
def self.up
rename_column :answers, :id_user, :user_id
rename_column :answers, :id_survey, :survey_id
rename_column :answers, :id_question, :question_id
end
def self.down
rename_column :answers, :user_id, :id_user
rename_column :answers, :survey_id, :id_survey
rename_column :answers, :question_id, :id_question
end
end
我重新启动控制台,还偏食,但什么都没有改变。
I restarted the console and also eclipse, but nothing changed.
软件本身工作正常的服务器上,那么为什么测试抛出这些错误的每个测试?
The app itself is working fine in the server, so why is the testing throwing those errors for every test?
我应该怎么办?先谢谢了。
What should I do? Thanks in advance.
推荐答案
检查夹具文件!每当我重新命名列,我经常忘记来调整我的灯具相匹配。这将导致每一个测试错误,就像你所看到的。
Check your fixtures file! Whenever I'd rename columns, I'd usually forget to tweak my fixtures to match. This causes an error on every single test, just like you're seeing.
希望帮助!
这篇关于更改表的列名之后的所有单元和功能测试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!