rake 数据库:迁移失败

发布于 01-01 03:09 字数 2932 浏览 6 评论 0原文

我正在创建一个简单的用户表,当我运行 rake db:migrate 时,它​​似乎是 create_table(:users) 但是我同时收到以下警告。我尝试再次运行 rake db:migrate ,然后在此页面上出现第二个错误。如何检查表是否已创建,以及如何防止此警告/错误?

ERROR1

    WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
    at /Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
WARNING: Global access to Rake DSL methods is deprecated.  Please include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method DemoApp::Application#task called at /Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/railties-3.0.1/lib/rails/application.rb:214:in `initialize_tasks'

ERROR 2

rake aborted!
undefined local variable or method `d' for main:Object

得到的结果

/Users/anderskitson/rails_project/demo_app/Rakefile:1:in `<top (required)>'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/rake:19:in `load'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/rake:19:in `<main>'

这是我通过 --trace我运行

rails 生成脚手架 用户名:string 电子邮件:string

然后我运行了

rake db:migrate

我的 rake 文件,如下所示

d# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'


DemoApp::Application.load_tasks

I am creating a simple users table and when I ran rake db:migrate it appeared to create_table(:users) Howerver I got the following warnings at the same time. I tried running rake db:migrate again and then I got the 2nd error on this page. How can I check if the table was created, and how to prevent this warning/error?

ERROR1

    WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
    at /Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
WARNING: Global access to Rake DSL methods is deprecated.  Please include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method DemoApp::Application#task called at /Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/railties-3.0.1/lib/rails/application.rb:214:in `initialize_tasks'

ERROR 2

rake aborted!
undefined local variable or method `d' for main:Object

This is what I get with --trace

/Users/anderskitson/rails_project/demo_app/Rakefile:1:in `<top (required)>'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/rake:19:in `load'
/Users/anderskitson/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/rake:19:in `<main>'

I ran

rails generate scaffold User name:string email:string

Then I ran

rake db:migrate

my rake file looks like

d# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'


DemoApp::Application.load_tasks

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

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

发布评论

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

评论(2

带上头具痛哭2025-01-08 03:09:28

删除 Rakefile 中的第一个字符 d

d# Add your own tasks in files placed in lib/tasks ending in .rake,

您会认出这一行,因为它是您粘贴的错误消息中指向的行号,您可以看出这是错误的部分该行的字母,因为它正是错误消息告诉您它无法识别的字母。

Remove the d which is the first character in your Rakefile:

d# Add your own tasks in files placed in lib/tasks ending in .rake,

You'll recognise this line because it's the line number which is pointed to in the error message you pasted, and you can tell that that's the erroneous part of the line because it's exactly the letter which the error message told you it couldn't identify.

茶色山野2025-01-08 03:09:28

这取决于您当前使用的 Rails 版本,但我建议生成一个新的 Rails 应用程序并复制生成的 Rakefile 以确保您是最新的。那里可能有一个 require "rake/rdoctask" 需要更改。

也就是说,此警告可能不会导致迁移失败。

使用 --trace 再次运行它以获取完整的堆栈跟踪。

It depends on the version of Rails that you're currently using, but I'd recommend generating a new Rails application and copying over the generated Rakefile to ensure you're up to date. There's likely a require "rake/rdoctask" in there that needs to be changed.

That said, this warning likely is not causing the migration failure.

Run it again with --trace to get the full stack trace.

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