I have two databases in use in a Ruby on Rails application; one is the database for the application while the second is an independent database over which Rails is not given control.
Problem is when loading fixtures into the dev, it tries to run DELETE statements on the tables in the independent database from the connection to the dev database, which obviously errors out.
I don’t want Rails to try to do ANYTHING but read the independent database – I especially don’t want it trying to delete tables.
Is there a simple way to tell Rails to ignore the models for the second database when loading fixtures?
UPDATE: To clarify, Rails seems to think the tables from the independent database are part of the development connection, though I have specified the correct connection in the model class using establish_connection. As another note, all model classes work precisely as desired from script/console.
Okay…my issue was that I used the
script/generateto create the models from the secondary database, which also created fixture, schema, test, and migrations files. I had removed the schema, test, and migrations files, but did not remove the generated fixtures (they were empty files) as I did not think it had created any.After removing all files (including the models) from the secondary database and re-running the migrations for the dev db, I added back only the model files and the database in
databases.ymlfrom the secondary db, which solved the issue.I still can’t explain why Rails’ rake tasks were looking in the wrong database and I am a little disappointed with rails’ addition of the
schema_migrationstable in the secondary database, which it obviously does not need.However, it works now.