Can't run 'db:seed'

I’ve just deployed a rails app and want to seed the database.

However, when I run this command:
fly ssh console -C "rails/bin/rails db:seed"

I get the following error:

Connecting to fdaa:2:5ac:a7b:a27f:7d3b:5332:2... complete
rails aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/command.rb:51:in `invoke'
/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/commands.rb:18:in `<main>'
<internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
rails/bin/rails:4:in `<main>'
(See full trace by running task with --trace)
Error: ssh shell: Process exited with status 1

Does anyone know what the issue might be?

Bad answer:

Summary

When you SSH into a fly machine, your initial directory is /, however (from what I can tell), your source code is placed in /app by the buildpack.

So you would need to run this instead: fly ssh console -C "rails/bin/rails -f /app/Rakefile db:seed".

That should do it, but let me know if it doesn’t work.

If you are running Rails 7, and using the generated Dockerfile you don’t need to run seed as docker-entrypoint will run db:prepare.

If you want to run db:seed anyway, you will need to adjust your bin stubs to set the current working directory. The command to do so can be found here: Dockerfiles and fly.toml · Fly Docs

Thanks for chiming in! I get the same error message as before :confused: No Rakefile found (looking for: /app/Rakefile)

That’s odd because I don’t see the specified seeds in the db.

Anyway, when I run this:

bin/rails generate dockerfile --bin-cd

From the link you sent, I was able to run this successfully:

fly ssh console -C "rails/bin/rails db:seed"

The command ran successfully and I now see the seed in the db.

Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.