Rake db:种子失败,"不知道如何构建任务db.seed"

Roy*_*Roy 3 ruby ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-4

当我运行rake db.seed时出现以下错误,我该如何解决?

(我尝试删除seed.rb并重新创建它,但它不起作用)

耙子流产了!不知道如何构建任务'db.seed'

/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task_manager.rb:62:in []' /Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:149:in invoke_task'/Users/ user/ .rbenv/versions/ 2.2.1/ lib/ruby /2.2.0/rake/application.rb:106: block (2 levels) in top_level' /Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in 每个'/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in block in top_level' /Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in run_with_threads'/ Users/user/.rbenv/versions/2.2.1/lib/ruby​​/2.2.0/rake/application.rb:100:top_level' /Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in in run in run' /Users/user/.rbenv/versions/2.2.1/lib/ ruby/2.2.0/rake/application.rb:176:在standard_exception_handling' /Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in 运行'/Users/user/.rbenv/versions/2.2.1/bin/rake : 33 : in`

背景资料:

我正在按照我在db.seed文件中创建模拟用户的教程.

User.create!电子邮件:'test@test.com',密码:'密码',密码_确认:'密码'

现在当我运行命令rake db:seed时,我得到上面的错误.如何成功运行命令?

K M*_*lam 6

为了避免将来出现此类错误,您可以bundle exec rake -T从项目目录中键入以列出Rails应用程序的所有可用rake任务:

?  bundle exec rake -T
rake db:create                          # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databa...
rake db:drop                            # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in...
rake db:fixtures:load                   # Load fixtures into the current environment's database
rake db:migrate                         # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rake db:migrate:status                  # Display status of migrations
rake db:rollback                        # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:cache:clear              # Clear a db/schema_cache.dump file
rake db:schema:cache:dump               # Create a db/schema_cache.dump file
rake db:schema:dump                     # Create a db/schema.rb file that is portable against any DB supported by AR
rake db:schema:load                     # Load a schema.rb file into the database
rake db:seed                            # Load the seed data from db/seeds.rb
Run Code Online (Sandbox Code Playgroud)

然后,只需复制您正在寻找的任务(rake db:seed在本例中)并运行rake任务!