雷克流产了!数据库名称错误?

发布于 2024-08-20 16:49:44 字数 3177 浏览 2 评论 0原文

我希望运行一些单元测试,但这就是我得到的。互联网对这个问题保持沉默。轨道2.1 如果有任何其他信息有帮助,请告诉我。

    mike@sleepycat:~/projects/myapp$ rake test:units --trace
    (in /home/mike/projects/myapp)
    ** Invoke test:units (first_time)
    ** Invoke db:test:prepare (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Invoke db:abort_if_pending_migrations (first_time)
    ** Invoke environment 
    ** Execute db:abort_if_pending_migrations
    ** Execute db:test:prepare
    ** Invoke db:test:clone (first_time)
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment 
    ** Execute db:schema:dump
    ** Invoke db:test:purge (first_time)
    ** Invoke environment 
    ** Execute db:test:purge
    rake aborted!
    Mysql::Error: Incorrect database name '': DROP DATABASE IF EXISTS ``
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:299:in `execute'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:384:in `drop_database'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:364:in `recreate_database'
    /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:315
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'

我的数据库.yml:

    # MySQL (default setup).  Versions 4.1 and 5.0 are recommended.
    #
    # Install the MySQL driver:
    #   gem install mysql
    # On MacOS X:
    #   gem install mysql -- --include=/usr/local/lib
    # On Windows:
    #   gem install mysql
    #       Choose the win32 build.
    #       Install MySQL and put its /bin directory on your path.
    #
    # And be sure to use new-style password hashing:
    #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
    development:
      adapter: mysql
      database: myapp_development
      username: root
      password: mikespass
      host: 127.0.0.1
      #socket: /tmp/mysql.sock

    # Warning: The database defined as 'test' will be erased and
    # re-generated from your development database when you run 'rake'.
    # Do not set this db to the same as development or production.
    test:
      adapter: mysql
      database: myapp_test
      username: root
      password: mikespass
      host: 127.0.0.1

    production:
      adapter: mysql
      database: myapp_production
      username: root
      password: 

    mikes:
      adapter: mysql
      database: myapp_development
      username: root
      password: mikespass
      host: 127.0.0.1

    staging:
      adapter: mysql
      database: myapp_development
      username: root
      password: mikespass
      host: 127.0.0.1

I was hoping to run some unit tests but this is what I am getting. The internets are silent on the issue. Rails 2.1
Let me know if there is any other info that would help.

    mike@sleepycat:~/projects/myapp$ rake test:units --trace
    (in /home/mike/projects/myapp)
    ** Invoke test:units (first_time)
    ** Invoke db:test:prepare (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Invoke db:abort_if_pending_migrations (first_time)
    ** Invoke environment 
    ** Execute db:abort_if_pending_migrations
    ** Execute db:test:prepare
    ** Invoke db:test:clone (first_time)
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment 
    ** Execute db:schema:dump
    ** Invoke db:test:purge (first_time)
    ** Invoke environment 
    ** Execute db:test:purge
    rake aborted!
    Mysql::Error: Incorrect database name '': DROP DATABASE IF EXISTS ``
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:299:in `execute'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:384:in `drop_database'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:364:in `recreate_database'
    /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:315
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'

My database.yml:

    # MySQL (default setup).  Versions 4.1 and 5.0 are recommended.
    #
    # Install the MySQL driver:
    #   gem install mysql
    # On MacOS X:
    #   gem install mysql -- --include=/usr/local/lib
    # On Windows:
    #   gem install mysql
    #       Choose the win32 build.
    #       Install MySQL and put its /bin directory on your path.
    #
    # And be sure to use new-style password hashing:
    #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
    development:
      adapter: mysql
      database: myapp_development
      username: root
      password: mikespass
      host: 127.0.0.1
      #socket: /tmp/mysql.sock

    # Warning: The database defined as 'test' will be erased and
    # re-generated from your development database when you run 'rake'.
    # Do not set this db to the same as development or production.
    test:
      adapter: mysql
      database: myapp_test
      username: root
      password: mikespass
      host: 127.0.0.1

    production:
      adapter: mysql
      database: myapp_production
      username: root
      password: 

    mikes:
      adapter: mysql
      database: myapp_development
      username: root
      password: mikespass
      host: 127.0.0.1

    staging:
      adapter: mysql
      database: myapp_development
      username: root
      password: mikespass
      host: 127.0.0.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何时共饮酒 2024-08-27 16:49:44

您似乎尚未在 config/database.yml 文件中为 test 环境指定数据库名称。

It looks like you haven't specified a database name for the test environment in your config/database.yml file.

我还不会笑 2024-08-27 16:49:44

无法在注释中结束行,所以我将其放在这里


您可以运行脚本/控制台然后执行以下操作:

@a = YAML::load(File.open("#{RAILS_ROOT}/config/database.yml"))

@a

然后粘贴@a的内容

cant end lines in comments so i'll just put it here


can you run script/console then do :

@a = YAML::load(File.open("#{RAILS_ROOT}/config/database.yml"))

@a

then paste the contents of @a

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文