Here are my models:
class Project < ActiveRecord::Base
has_many :gs_collectors, dependent: :destroy
class GsCollector < ActiveRecord::Base
belongs_to :project
has_one :application, dependent: :destroy
class Application < ActiveRecord::Base
belongs_to :gs_collector
Here’s my factories:
factory :application do
....
association :gs_collector
association :dust_type
end
factory :gs_collector do
...
association :project
end
factory :project do
sequence(:name) { |n| "Project#{n}" }
contact_name 'John Customer'
end
The Application model used to belong_to Project, so I just used a migration to change project_id to gs_collector_id in the db. But, now I get this error when trying to run any of my tests (even on units/controllers that have no relation to the application model):
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'project' in 'field list': INSERT INTO `applications` (`project`, ....
Why am I getting this error?
If I add this line back in to my Application model:
belongs_to :project
Everything works good again. But it shouldn’t be necessary anymore.
What am I missing here?
The problem here was that I had a fixtures file that was created by the scaffold generator. Once I removed the fixtures file, everything worked great.