Heroku run rake db:migrate command error - ruby-on-rails

I created rails app follow this guid https://devcenter.heroku.com/articles/rails4-getting-started. But when I run Heroku run rake db:migrate command return error : Error: Permission denied - connect(2) (Errno::EACCES)
UPDATED
migration
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :tilte
t.timestamps
end
end
end
UPDTE 2
heroku config
=== powerful-eyrie-5396 Config Vars
DATABASE_URL: postgres://bqfsdarajfpdlk:4nU5FON87juyFwSdaX7Sr3Aicl#ec2-54-225-89-245.compute-1.amazonaws.com:5432/d65593ob81m9g8
HEROKU_POSTGRESQL_COBALT_URL: postgres://bqfsdarajfpdlk:4nU5FON87juyFwSdaX7Sr3Aicl#ec2-54-225-89-245.compute-1.amazonaws.com:5432/d65593ob81m9g8
UPDATE 3 heroku command backtrace
Error: Permission denied - connect(2) (Errno::EACCES)
Backtrace: /var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/client/rendezvous.rb:40:in `initialize'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/client/rendezvous.rb:40:in `open'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/client/rendezvous.rb:40:in `block in start'
/opt/rh/ruby193/root/usr/share/ruby/timeout.rb:69:in `timeout'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/client/rendezvous.rb:31:in `start'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/command/run.rb:132:in `rendezvous_session'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/command/run.rb:119:in `run_attached'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/command/run.rb:24:in `index'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/command.rb:206:in `run'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/lib/heroku/cli.rb:28:in `start'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/gems/heroku-2.39.4/bin/heroku:17:in `<top (required)>'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/bin/heroku:23:in `load'
/var/lib/stickshift/51bef7595973caa43f000531/app-root/data/lib/ruby/gems/bin/heroku:23:in `<main>'

This question was resolved this command:
heroku run:detached rake db:migrate

Try to reset your database first
heroku pg:reset DATABASE
then
heroku run rake db:migrate

Related

my rails db:migrate isnt working

i tried running rake bd:migrate but it gave me an error and told me to run rails db:migrate RAILS_ENV=development instead but it gave me bunch of errors
C:\Sites\seekhostel.com>rails db:migrate RAILS_ENV=development
== 20180311182801 AddDeviseToUsers: migrating =================================
-- change_table(:users)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:7:in `block in up'
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:7:in `block in up'
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
SQLite3::SQLException: duplicate column name: email
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:7:in `block in up'
C:/Sites/seekhostel.com/db/migrate/20180311182801_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
i would love to know why it did so and how to fix it
By looking at error message I suspect two things happened here:
You already had users table (because new migration has change_table(:users), not create_table(:users) - devise generator recognize that)
You ran $ rails generate devise command and you didn't inspect autogenerated migration file.
You were supposed to remove line
t.string :email, null: false, default: ""
from 20180311182801_add_devise_to_users.rb file

Ruby on rails migration error

I installed a gem acts-as-taggable-on whenever i tried to run rails db:migrate it would output this:
C:\Sites\novosti>rails db:migrate
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
So i just added [5.1] and it fixed the problem but another one appeared
C:\Sites\novosti>rails db:migrate
== 20170708123900 ActsAsTaggableOnMigration: migrating ========================
-- create_table(:tags)
-> 0.0028s
-- create_table(:taggings)
-> 0.0033s
-- add_index(:taggings, :tag_id)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Index name 'index_taggings_on_tag_id' on table 'taggings' already exists
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
ArgumentError: Index name 'index_taggings_on_tag_id' on table 'taggings' already exists
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Index name on a table should be unique. So this is an error from db as the the index already exists. Please drop the index on the table of the db before migration or you can remove the add_index in migration if the index is already ok in the table

Cannot use db Migrate, rake aborted error

I am working a new project in Codeanywhere (I am new on Ruby), but when I try to use "rake db : migrate" I have this error:
rake aborted!
Don't know how to build task ':' (see --tasks)
/home/cabox/.rvm/gems/ruby-2.1.2/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
Before this I use bundle update and after and nothing, and when I put "rake-T", db Migartion is on the tasks, when I try with --trace, pass the same.
I try before with rake db:migrate and the same happened
`rake aborted!
SyntaxError:
/home/cabox/workspace/blog/db/migrate/20170103233409_create_posts.rb:5: syntax error, unexpected ':'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:761:in `load_migration'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord- 4.1.6/lib/active_record/migration.rb:757:in `migration'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:752:in `disable_ddl_transaction'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:1044:in `use_transaction?'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:1036:in `ddl_transaction'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:990:in `execute_migration_in_transaction'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:952:in `block in migrate'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:948:in `each'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:948:in `migrate'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `up'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:785:in `migrate'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/home/cabox/.rvm/gems/ruby-2.1.2/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)` >
Does anyone know how to solve this problem?
In the migration file I have:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.strind :
t.text :body
t.timestamps
end
end
end
I am pretty sure what is happening is you are inserting a space in there when you type it out. It needs to be
rake db:migrate
not
rake db : migrate
That error message is pretty common when there is a spelling error or some other kind of typing error when running the command.
Your migration has a typo as well, should be this
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
Rake is a software task management tool, similar to Make, etc. in other systems
The generic syntax is
rake namesapce:task
In your case it is
rake db:migrate
Try doing rake db:reset if you want to rebuild your db again. It does 4 things for you
rake db:drop
rake db:create
rake db:migrate
rake db:seed

rake db:test:prepare erroring out due to PG error

Some of my rSpec tests are failing and I suspect it's due to the test database not being cleared out. When I try to run rake db:test:prepare, I'm getting the error below (i'm in Rails 3.2). Clearly, this looks like some kind of Postgres issue, looks like the rake task is trying to drop the test database so it can repopulate it. Production database schema loads fine.
I've looked for the rake task in lib/tasks/ but I haven't been able to find it. Anyone have any idea on what's going on?
osx_user-> rake db:test:prepare
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DROP DATABASE IF EXISTS ""
^
: DROP DATABASE IF EXISTS ""
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
Figured it out. My database.yml file for the development environment was set like this:
database: <%= ENV['DATABASE_NAME_TEST'] %>
The rake task was looking for an environmental variable that did not exist.

undefined method `run' for main:Object

i'm getting the following output when deploying:
cap aborted!
NoMethodError: undefined method `run' for main:Object
config/deploy.rb:37:in `block (2 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/dsl/task_enhancements.rb:12:in `block in after'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
Tasks: TOP => deploy:permissions
(See full trace by running task with --trace)
The deploy has failed with an error: #<NoMethodError: undefined method `run' for main:Object>
i'm using Capistrano Version: 3.2.1 (Rake Version: 10.3.2).
the deploy works fine but i created a after deploy task to modify the owner of the deployed release which looks so:
namespace :deploy do
task :permissions do
run "chown -R :#{fetch(:group)} #{deploy_to} && chmod -R g+s #{deploy_to}"
end
end
after :deploy, "deploy:permissions"
vars are defined correctly (i fixed that error before) but i get this missing method error for the run method and i dont know why.
Your code uses 2.x syntax, while your version is 3.x. In 3.x, the syntax looks like this:
namespace :deploy do
on roles :all do
execute :chown, "-R :#{fetch(:group)} #{deploy_to} && chmod -R g+s #{deploy_to}"
end
end

Resources