Polydectes
2009-Aug-11 04:31 UTC
rake db:schema:load insists on querying my database for data I haven''t loaded.
Rails 2.3.2. Ruby 1.8.7. MySQL 5.x I have used "rake db:schema:dump" to generate a migration structure to go from development to production. I want to use "rake db:schema:load" to load it into my new database. Sounds like a plan. When I run "rake db:schema:load" on the new database (development or production), I get the following error: <from development test> rake aborted! Mysql::Error: Table ''mojo_development.statuses'' doesn''t exist: SELECT * FROM `statuses` WHERE (`statuses`.`name` = ''New'') LIMIT 1 (production gives the same, but database name is mojo_production). The Select is not in the schema. If I trace it back, I find the Select is generated from the following method in my Mojo model: def self.new_state for_name(''New'').first end where for_name is a :named_scope generating the select statement above. So my questions are: 1) WHY does db:schema:load run queries against my database when the data (and tables) aren''t there? and 2) HOW do I fix this so it won''t happen again?
Matt Jones
2009-Aug-11 12:53 UTC
Re: rake db:schema:load insists on querying my database for data I haven''t loaded.
Posting the results of running the rake command with --trace always helps, but I''d say the likely culprit here is something in your environment / initializers. Does that function get called from environment.rb or an initializer? --Matt Jones On Aug 11, 12:31 am, Polydectes <esmith...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Rails 2.3.2. Ruby 1.8.7. MySQL 5.x > > I have used "rake db:schema:dump" to generate a migration structure to > go from development to production. I want to use "rake > db:schema:load" to load it into my new database. Sounds like a plan. > > When I run "rake db:schema:load" on the new database (development or > production), I get the following error: > > <from development test> > rake aborted! > Mysql::Error: Table ''mojo_development.statuses'' doesn''t exist: SELECT > * FROM `statuses` WHERE (`statuses`.`name` = ''New'') LIMIT 1 > > (production gives the same, but database name is mojo_production). > > The Select is not in the schema. If I trace it back, I find the > Select is generated from the following method in my Mojo model: > > def self.new_state > for_name(''New'').first > end > > where for_name is a :named_scope generating the select statement > above. > > So my questions are: > > 1) WHY does db:schema:load run queries against my database when the > data (and tables) aren''t there? > > and > > 2) HOW do I fix this so it won''t happen again?
Ilan Berci
2009-Aug-11 19:51 UTC
Re: rake db:schema:load insists on querying my database for data I haven''t loaded.
Eric Smith wrote:> Rails 2.3.2. Ruby 1.8.7. MySQL 5.x > > I have used "rake db:schema:dump" to generate a migration structure to > go from development to production. I want to use "rake > db:schema:load" to load it into my new database. Sounds like a plan. > > When I run "rake db:schema:load" on the new database (development or > production), I get the following error: >Your rake task is picking up your development environment from config/environment.rb. Here''s what you can do to start off with a clean production schema provided you are the only one working on your db and you have foolishly/wisely modified your db schema without going through a proper migration strategy.. 1) perform a rake db:schema:dump 2) remove all prior migration files 3) perform a rake db:migrate 4) open the migration file just created, and cut and paste the contents from the schema.rb file that you created in step 1. (during the paste, just copy the relevant parts, avoid the database create part..) 5) Now you can use that migration file on production 6) Ask that girl in finance out on a date like you promised yourself 2 weeks ago. hth ilan -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Aug-11 20:04 UTC
Re: rake db:schema:load insists on querying my database for data I haven''t loaded.
On Aug 11, 5:31 am, Polydectes <esmith...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 1) WHY does db:schema:load run queries against my database when the > data (and tables) aren''t there? > > and > > 2) HOW do I fix this so it won''t happen again?rake db:schema:load requires the environment task (which loads your app config and so on) in production config.cache_classes is true, which means that your applications models are loaded your Mojo model is loaded, and reaches the line named_scope :some_scope, :conditions => {.... self.new_state } which runs your new_state ,method, which queries the database One possible solution: alter your environment so that cache classes doesn''t get set to true in cases like this. I outlined a few ways of doing this at http://www.spacevatican.org/2008/12/28/when-cache_classes-gets-you-down Fred