简体   繁体   English

rake db:seed不能使用neo4j gem

[英]rake db:seed is not working using neo4j gem

I have stated working on neo4j with rails using the gem 'neo4j', I want to seed some data in neo4j database. 我已经声明使用gem'neo4j'在rails上使用rails进行工作,我想在neo4j数据库中播种一些数据。 But whenever I am trying to do rake db:seed, it says 但是每当我试图做rake db:seed时,它说

rake aborted!
Don't know how to build task 'db:seed'

I have checked all the rake tasks using rake -T , and there is no rake db:seed. 我已经使用rake -T检查了所有rake任务,并且没有rake db:seed。

Does any one have any idea? 有谁有想法吗?

The Neo4j gem doesn't have a seed command. Neo4j gem没有种子命令。 The command you're trying to use is provided by ActiveRecord. 您尝试使用的命令由ActiveRecord提供。 We'd love to add this functionality in, though, and if you'd like to help, we'd gladly accept a PR and/or contribute to the process. 不过,我们很乐意添加此功能,如果您愿意提供帮助,我们很乐意接受PR和/或为此过程做出贡献。 For now, open up an issue at https://github.com/neo4jrb/neo4j/issues and we can add it to the roadmap. 目前,请在https://github.com/neo4jrb/neo4j/issues上打开一个问题,我们可以将其添加到路线图中。

Finally got the solutions. 终于得到了解决方案。

Create a file seed.rake under lib/tasks and put the code lib / tasks下创建一个文件seed.rake并放入代码

namespace :db do
  desc 'Load the seed data from db/seeds.rb'
  task :seed => :environment do
    seed_file = File.join(Rails.root, 'db', 'seeds.rb')
    load(seed_file) if File.exist?(seed_file)
  end
end

Check apps root directory, is there a Rakefile? 检查应用程序根目录,是否有Rakefile?
Make a file with name "Rakefile" and enter these line 创建一个名为“Rakefile”的文件并输入这些行

"#!/usr/bin/env rake “#!/ usr / bin / env rake
require File.expand_path('../config/application', FILE ) require File.expand_path('../ config / application', FILE
APP_NAME::Application.load_tasks APP_NAME :: Application.load_tasks

As others mentioned before, rails db:seed is a built-in feature backed by ActiveRecord . 正如其他人之前提到的, rails db:seed是一个由ActiveRecord支持的内置功能。 Assuming you are using neo4jrb without ActiveRecord , you won't be able to use this command to seed database any more. 假设您使用的是没有ActiveRecord neo4jrb,您将无法再使用此命令为数据库设定种子。

However, you can use seedbank gem to recover this ability. 但是,您可以使用seedbank gem来恢复此功能。

It does not depend on ActiveRecord like seed_fu and other seeding gems do. 它不依赖于像seed_fu和其他播种宝石那样的ActiveRecord So it will work just fine with neo4jrb. 因此它可以与neo4jrb一起使用。

The process is rather simple. 这个过程相当简单。

  1. put seedbank in your Gemfile and bundle install. 将seedbank放入Gemfile并捆绑安装。
  2. create directory db/seeds/ 创建目录db/seeds/
  3. create a seeds file under the db/seeds/ directory db/seeds/目录下创建一个种子文件

for example 例如

#db/seeds/show.seeds.rb

Show.create(name: "Better Call Saul", producer: "Vince Gilligan")
  1. run rake db:seed:show 运行rake db:seed:show

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM