问题
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:
Example:
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.
回答1:
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.
Hope that helps!
来源:https://stackoverflow.com/questions/11065752/error-in-all-unit-and-functional-tests-after-altering-column-names-of-a-table