English 中文(简体)
mysql + ruby = nightmare
原标题:

Ok, I m done. I can t understand why I got this error with:

rake features

It cant be I can t connect to mysql cause the:

rake db:migrate

works perfectly.

I keep having this error:

rake features --trace
(in /Users/myname/Projects/rails_app)
** Invoke features (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment 
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment 
** Execute db:schema:load
rake aborted!
closed stream
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:1032:in `sync= 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:1032:in `write 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:1092:in `finalizer 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:578:in `call 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:578:in `start 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:578:in `free 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:438:in `tables 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:24:in `table_exists? 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:106:in `create_table 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:473:in `create_table 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `send 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `method_missing 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/migration.rb:348:in `method_missing 
/Users/myname/Projects/rails_app/db/schema.rb:38
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/schema.rb:43:in `instance_eval 
/Users/myname/Projects/rails_app/vendor/rails/activerecord/lib/active_record/schema.rb:43:in `define 
/Users/myname/Projects/rails_app/db/schema.rb:12
/Users/myname/Projects/rails_app/vendor/rails/activesupport/lib/active_support/dependencies.rb:145:in `load_without_new_constant_marking 
/Users/myname/Projects/rails_app/vendor/rails/activesupport/lib/active_support/dependencies.rb:145:in `load 
/Users/myname/Projects/rails_app/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in 
/Users/myname/Projects/rails_app/vendor/rails/activesupport/lib/active_support/dependencies.rb:145:in `load 
/Users/myname/Projects/rails_app/vendor/rails/railties/lib/tasks/databases.rake:259
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke 
/Users/myname/Projects/rails_app/vendor/rails/railties/lib/tasks/databases.rake:304
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke 
/Users/myname/Projects/rails_app/vendor/rails/railties/lib/tasks/databases.rake:378
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run 
/Users/myname/.gem/ruby/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load 
/usr/bin/rake:19

My machine: Mac OS X 10.5.8 ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] Rails 2.3.4 mysql (2.8.1) [rubygem] Mysql path: /opt/local/lib/mysql5 [installed via macport]

Thank you so much!

问题回答

Save your DBs and reinstall mysql. Follow http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/ Made all my problems go away.

I have to theories about your problem, but no reason to suspect either is really your cause, but they re quick checks.

  1. You haven t properly defined the testing database in config/databases.yml

  2. The mysql user that is attempting to build this database lacks the permission to do so.

Can you connect to the database in question with the credentials in question (all the stuff in database.yml)?
"mysql -u your_user -p" from the command line?

When you installed the mysql gem did it properly build the native extensions? What happens when you gem install mysql --force (to re-install it)? Does it look happy?

Have you ever done this before? Is the problem as likely to be a lack of experience with rails/mysql or both? Or is this old hat and you just can t figure it out this time?

If the former, the tutorial in the pragramatic agile web development with rails is quite good (as is the rest of the book).

Hope something there helps.

Please tell the output of:

rake db:schema:load RAILS_ENV=test

to be sure that an existing database named _test is configured and working under config/database.yml





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签