Cannot use heroku run rake db:migrate in rails? - ruby-on-rails

sahilrd07:~/workspace/sample2 (filling-in-layout) $ heroku run rake db:drop
Running rake db:drop on limitless-coast-42827... up, run.4760
rake aborted!
NameError: uninitialized constant Sass::Script
/app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass/rails/helpers.rb:11:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass/rails.rb:8:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass/rails.rb:8:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass-rails.rb:1:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass-rails.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler.rb:134:in `require'
/app/config/application.rb:7:in `<top (required)>'
/app/Rakefile:4:in `require'
/app/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

You should enter your Heroku server and run the command there:
$ heroku console
Ruby console for heroku-project-name
>> ActiveRecord::Migration.drop_table(:table_name)

As described here, you can also drop the db from your heroku dashboard. From the linked post:
Now it's also possible to reset the database through their web interface.
Go to dashboard.heroku.com select your app and then you'll find the database under the add-ons category, click on it and then you can reset the database.

Related

rails db:setup error : rails aborted ? I am using postgresql and postico 2

I am newbie with Rails and here is my problem. I setup a new rails program named freelancer02 and in the file database.yml I saw the database : freelancer02_development and database : freelancer02_test
So I think, I could run this command to setup a new database
rails db:setup
But it gave me this error
rails aborted!
LoadError: incompatible library version - /Users/anhbui/.gem/ruby/3.1.2/gems/pg-1.4.5/lib/pg_ext.bundle
/Users/xxx/.gem/ruby/3.1.2/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/Users/xxx/.gem/ruby/3.1.2/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/Users/xxx/.gem/ruby/3.1.2/gems/pg-1.4.5/lib/pg.rb:49:in `block in <module:PG>'
/Users/xxx/.gem/ruby/3.1.2/gems/pg-1.4.5/lib/pg.rb:37:in `block in <module:PG>'
/Users/xxx/.gem/ruby/3.1.2/gems/pg-1.4.5/lib/pg.rb:42:in `<module:PG>'
/Users/xxx/.gem/ruby/3.1.2/gems/pg-1.4.5/lib/pg.rb:6:in `<main>'
/Users/xxx/.gem/ruby/3.1.2/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/Users/xxx/.gem/ruby/3.1.2/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/Users/xxx/.gem/ruby/3.1.2/gems/bundler-2.3.26/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
/Users/xxx/.gem/ruby/3.1.2/gems/bundler-2.3.26/lib/bundler/runtime.rb:55:in `each'
/Users/xxx/.gem/ruby/3.1.2/gems/bundler-2.3.26/lib/bundler/runtime.rb:55:in `block in require'
/Users/xxx/.gem/ruby/3.1.2/gems/bundler-2.3.26/lib/bundler/runtime.rb:44:in `each'
/Users/xxx/.gem/ruby/3.1.2/gems/bundler-2.3.26/lib/bundler/runtime.rb:44:in `require'
/Users/xxx/.gem/ruby/3.1.2/gems/bundler-2.3.26/lib/bundler.rb:186:in `require'
/Users/xxx/Desktop/Rails/freelancer02/config/application.rb:7:in `<main>'
/Users/xxx/Desktop/Rails/freelancer02/Rakefile:4:in `require_relative'
/Users/xxx/Desktop/Rails/freelancer02/Rakefile:4:in `<main>'
/Users/xxx/.gem/ruby/3.1.2/gems/railties-7.0.4/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/Users/xxx/.gem/ruby/3.1.2/gems/railties-7.0.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/xxx/.gem/ruby/3.1.2/gems/railties-7.0.4/lib/rails/command.rb:51:in `invoke'
/Users/xxx/.gem/ruby/3.1.2/gems/railties-7.0.4/lib/rails/commands.rb:18:in `<main>'
/Users/xxx/.gem/ruby/3.1.2/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/Users/xxx/.gem/ruby/3.1.2/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
I also ran this command
rake db:reset RAILS_ENV=test
but it still gave me the error above
When I check by ruby -v and rails -v, my version is ruby 3.1.2 and rails 7.0.4
Could you please give me some advices ? Thank you very much for your time.

New to SQL / Ruby on Rails - database created, schema dumb error

I'm working on teaching myself both SQL & Ruby on Rails, and just starting out. I'm following a tutorial and successfully created a new SQL database and user, as well as a project.
The next step was to run a schema dump (even though the database is empty at the moment) just to confirm that the project could talk to the new database. Unfortunately it is a no go. I can see the database listed in my config/database.yml, and it contains the proper references to both the user and the database, but for some reason the schema dump fails.
Below are my commands, followed by the error, followed by the command again with a trace. I really appreciate any help you can offer.
C:\Users\Danny\Documents\Sites\demo_project>rails db:schema:dump
rails aborted!
LoadError: cannot load such file -- mysql2/2.4/mysql2
C:/Users/Danny/Documents/Sites/demo_project/config/application.rb:7:in `<top (required)>'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `require_relative'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
C:\Users\Danny\Documents\Sites\demo_project>rails db:schema:dump --trace
rails aborted!
LoadError: cannot load such file -- mysql2/2.4/mysql2
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `require'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `<top (required)>'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:81:in `require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:81:in `block (2 levels) in require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:76:in `each'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:76:in `block in require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:65:in `each'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler/runtime.rb:65:in `require'
C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/bundler.rb:114:in `require'
C:/Users/Danny/Documents/Sites/demo_project/config/application.rb:7:in `<top (required)>'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `require_relative'
C:/Users/Danny/Documents/Sites/demo_project/Rakefile:4:in `<top (required)>'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:703:in `raw_load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:104:in `block in load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:103:in `load_rakefile'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.0.7/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
In the below mentioned command you need compile yourself
C:\Users\xxxx\xxxx>gem install mysql2 --platform=ruby -- '--with-mysql-lib="I:\mysql-5.7.19-winx64\lib" --with-mysql-include="I:\mysql-5.7.19-winx64\include"'
If you still got the error then you might need to downgrade to 2.3 for mysql support.
For the mysql compatibility for rails on windows..please find below the github link:
https://github.com/brianmario/mysql2/issues/861

Running RoR on Fedora, get: undefined local variable or method `ext_dir' for

I'm trying to install Catarse.me on a Fedora 19 machine, ready to be pushed to Heroku.
I've managed to successfully run bundle install. But when I try
rake db:migrate
I receive this error
[root#acer]$ rake db:migrate
rake aborted!
undefined local variable or method `ext_dir' for #<Gem::Specification:0x450c8ce RedCloth-4.2.9>
/home/user/rails/catarse/config/boot.rb:7:in `<top (required)>'
/home/user/rails/catarse/config/application.rb:1:in `<top (required)>'
/home/user/rails/catarse/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
I've individually checked each of these files, and on the lines noted there's a call to
variablename = File.expand_path('../path/to/Gemfile', __FILE__)
CORRECTION The stack trace points to line 7 in book.rb
Bundler.setup
I've googled but the only relevant hit is this StackOverflow question but whose situation and answer is unrelated to my problem.
I'd appreciate the help.
Running rake db:migrate -- trace gives
rake aborted!
undefined local variable or method `ext_dir' for #<Gem::Specification:0x4700158 RedCloth-4.2.9>
/usr/local/share/ruby/site_ruby/rubygems/specification.rb:1887:in `method_missing'
/usr/share/gems/gems/bundler-1.3.1/lib/bundler/rubygems_ext.rb:42:in `load_paths'
/usr/share/gems/gems/bundler-1.3.1/lib/bundler/runtime.rb:37:in `block in setup'
/usr/share/gems/gems/bundler-1.3.1/lib/bundler/runtime.rb:19:in `setup'
/usr/share/gems/gems/bundler-1.3.1/lib/bundler.rb:120:in `setup'
/home/mei/rails/catarse/config/boot.rb:7:in `<top (required)>'
/usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/mei/rails/catarse/config/application.rb:1:in `<top (required)>'
/usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/mei/rails/catarse/Rakefile:4:in `<top (required)>'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/share/gems/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/usr/local/share/gems/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/bin/rake:23:in `load'
/bin/rake:23:in `<main>'
By your trace, it seems like it's a bundler issue,
running
gem update bundler
should fix it.

errors with rake db:create command in ruby on rails

when I have typed command rake db:create, following errors were displayed on terminal
rake aborted!
cannot load such file -- active_support/core_ext/class/inheritable_attributes
/home/shashikant/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385/gems/supermodel-0.1.4/lib/supermodel.rb:5:in `<top (required)>'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385#global/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
/home/shashikant/railsproject/online_exams_system/config/application.rb:7:in `<top (required)>'
/home/shashikant/railsproject/online_exams_system/Rakefile:5:in `require'
/home/shashikant/railsproject/online_exams_system/Rakefile:5:in `<top (required)>'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `eval'
/home/shashikant/.rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `<main>'
(See full trace by running task with --trace)
I got the answer just downloded the file "inheritable_attributes.rb" form github and other file name will be shown after u add the file in specified directory and run the command rake db:migrate

something wrong with my rails app deploy to heroku

I do my deploy as the heroku guide.
But when I use commend 'heroku rake db:migrate', then present these errors:
Running rake db:migrate attached to terminal... up, run.1
(in /app)
rake aborted!
no such file to load -- test/unit/error
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/app/.gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `block in require'
/app/.gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/app/.gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/app/.gems/gems/activesupport-2.2.2/lib/active_support/deprecation.rb:224:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/app/.gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `block in require'
/app/.gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/app/.gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/app/.gems/gems/activesupport-2.2.2/lib/active_support.rb:37:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/app/.gems/gems/rails-2.2.2/lib/tasks/misc.rake:11:in `<top (required)>'
/app/.gems/gems/rails-2.2.2/lib/tasks/rails.rb:4:in `load'
/app/.gems/gems/rails-2.2.2/lib/tasks/rails.rb:4:in `block in <top (required)>'
/app/.gems/gems/rails-2.2.2/lib/tasks/rails.rb:4:in `each'
/app/.gems/gems/rails-2.2.2/lib/tasks/rails.rb:4:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/app/Rakefile:10:in `<top (required)>'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/ruby1.9.2/bin/rake:31:in `<main>'
jason#jason-VirtualBox:~/work/depot$ rake db:migrate
(in /home/jason/work/depot)
I visit my app in heroku, it presents the error:
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
Try adding pg gem in gem file for the production environment and execute the below command
$ bundle install --without production
Since Heroku uses Postgresql databases we must use this way. Hope helps you.

Resources