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
Related
I'm trying to migrate the rails app but it fail. the issue in the paperclip gem migration.
I tried to use both way for migration but both of them not work properly:
class AddAttachmentImageToItems < ActiveRecord::Migration[6.1]
def self.up
add_attachment :items, :image
end
def self.down
remove_attachment :items, :image
end
end
also tried:
class AddAttachmentImageToItems < ActiveRecord::Migration[6.1]
def change
add_attachment :items, :image
end
end
after run rails db:migrate showing error:
/Users/zi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/pry-byebug-3.8.0/lib/pry-byebug/control_d_handler.rb:5: warning: control_d_handler's arity of 2 parameters was deprecated (eval_string, pry_instance). Now it gets passed just 1 parameter (pry_instance)
== 20210713231704 AddAttachmentImageToItems: migrating ========================
-- add_attachment(:items, :image)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (given 4, expected 3)
/Users/zi/rails/stage_1/db/migrate/20210713231704_add_attachment_image_to_items.rb:3:in `up'
/Users/zi/rails/stage_1/bin/rails:5:in `<top (required)>'
/Users/zi/rails/stage_1/bin/spring:10:in `block in <top (required)>'
/Users/zi/rails/stage_1/bin/spring:7:in `<top (required)>'
Caused by:
ArgumentError: wrong number of arguments (given 4, expected 3)
/Users/zi/rails/stage_1/db/migrate/20210713231704_add_attachment_image_to_items.rb:3:in `up'
/Users/zi/rails/stage_1/bin/rails:5:in `<top (required)>'
/Users/zi/rails/stage_1/bin/spring:10:in `block in <top (required)>'
/Users/zi/rails/stage_1/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Found the issue in the ruby version, downgrade to 2.6.8 and migration work properly.
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
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
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
A few days ago I created a migration for rails to add Paperclip avatars, but ended up going a different direction. Being new to Rails, I didn't know how bad of an idea it was to delete the migration file like I did.
My app works fine locally, but when run heroku run rake db:migrate I get this:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x000000046092e0>
It is because it is trying to run a migration called AddAttachmentAvatarToVenues, which is the migration I stupidly deleted.
It was also adding columns for the avatars that were specified in the deleted migration to the schema.rb, but I created a new migration to get rid of these. The new migration got rid of them but didn't change the heroku migration error.
Any idea how to fix this? I've done lots of googling and looking around SO and while there a lot of people with similar errors they are mostly problems with the commands that they're using.
Here is the output after the deleted migration attempted in my heroku migration.
== AddAttachmentAvatarToVenues: migrating ====================================
-- change_table(:venues)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x00000003bdb7c8>
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:4:in `block in up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:in `change_table'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:466:in `block in method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `block in say_with_time'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `say_with_time'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:458:in `method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:334:in `method_missing'
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:3:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:370:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:389:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:528:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `block in ddl_transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `ddl_transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:719:in `block in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:570:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:551:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I do see what's wrong with the output, I'm just not sure how to fix it without messing it up more.
EDIT: Here's some screenshots of file structure:
(The two similarly named ones are because there was a column I forgot to remove, but this was after I was having this problem and didn't affect it either way)
EDIT2:
Here's the deleted migration from my git history. I had added some more channels after this. They were just a couple of strings, but if that could make a difference I'll find a newer version.
class AddAttachmentAvatarToVenues < ActiveRecord::Migration
def self.up
change_table :venues do |t|
t.attachment :avatar
end
end
def self.down
drop_attached_file :venues, :avatar
end
end
Thanks in advance!
Perhaps you should look into this: How to empty DB in heroku
All your normal commands are also available in heroku, the only difference is that you have to put heroku run in front of it.
If your application hasn't gone live yet you could simply reset the database:
heroku pg:reset SHARED_DATABASE --confirm NAME_OF_THE_APP
And recreate it, using:
heroku run rake db:migrate
To seed the database:
heroku run rake db:seed
And lastly, to restart Heroku:
heroku restart
P.S. If these steps don't help, you could try running "heroku run rake db:setup" after dropping the database