I have a very annoying problem with my migrations.
First the Errormessage:
bundle exec rake db:migrate --trace
(in /home/myhomefolder/msdnaa)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
An error has occurred, all later migrations canceled:
uninitialized constant Computers
Now i have the assumption that an Update made by one of our admins is the reason why this happens every time. Even if there are no migrations at all!
What i've done (besides searching on Stack Overflow for a solution) is to grep every single file for "Computers".
Of course there are some Files containing this word and i checked them for Syntax Errors and the usual Stuff like missing ":".
Then i asked a workmate for some help (he is much more skilled with ruby than i am) and he hasn't a clue, everything looks right.
I'm using a slightly old Version of Ruby (1.8.7) and Rails (3.0.9), but i have no rights to do an update on our Server, so i have to deal with it.
And yes i asked the admin to do an update to 1.9.x and 3.1.x, but that can't be the fault 'cause it worked fine last week.
So it's one of those Errors where it SHOULD work, but it doesn't and i bet the solution is easy as drinking water, but i don't see it!
Any suggestions?
EDIT: Here ist the --trace:
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:113:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `each'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/core_ext/strin g/inflections.rb:43:in `constantize'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:407 :in `load_migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:402 :in `migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:397 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:539 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `call'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `ddl_transaction'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:538 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `each'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:435 :in `up'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:417 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/railties/databas es.rake:142
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_ chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_ chain'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_tas k'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/bin/rake:32
/var/lib/gems/1.8/bin/rake:19:in `load'
/var/lib/gems/1.8/bin/rake:19
Tasks: TOP => db:migrate
My guess is that you have just added a migration called something like 20120221123456_computers.rb, and within it, you have something like...
class SomeNameThatsNotComputers < ActiveRecord::Migration
...
When Rails executes a migration, it expects to execute the file, which defines the class, and then instantiate the class, and call #up or #down on that class instance. How does Rails know what class to instantiate? It's supposed to correspond with the part of the file name following the numeric prefix and underscore, so for a file name like 20120221123456_computers.rb, the class name must be Computers.
As you said grep tells existence of "Computers" that's the problem. It means Computers is not defined but getting used. migration loads the app environment first and that time it fails bcoz Computers is not initialized
Related
i have a rake task as follows-
desc 'send fetch request'
task send_fetch_request: :environment do
FacebookCrawl.new.process
end
Yesterday this task working, but I don't know why it is not working today.
I am trying to execute this with the below command-
rake send_fetch_request
Class details:
class FacebookCrawl
def initialize
fb_config = YAML.load_file(Rails.root.join("config/facebook_catalog.yml"))
#access_token = fb_config["facebook"]["access_token"]
#product_feed_ids = fb_config["facebook"]["product_feed_ids"]
end
def process
#product_feed_ids.each do |key,value|
feed_id = value["id"]
feed_url = value["feed_url"]
make_request(feed_id,feed_url,#access_token)
end
end
end
I am getting below error:
rake send_fetch_request --trace
** Invoke send_fetch_request (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute send_fetch_request
rake aborted!
NameError: undefined local variable or method ` FacebookCrawl' for main:Object
/Users/raj.sharma/Documents/Developer/Feed/lib/tasks/facebook_fetch_request_task.rake:3:in `block in <top (required)>'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `call'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/Users/raj.sharma/.rbenv/versions/2.2.2/bin/rake:22:in `load'
/Users/raj.sharma/.rbenv/versions/2.2.2/bin/rake:22:in `<main>'
Tasks: TOP => send_fetch_request
Yesterday it was working fine, I don't why rake is complaining today. Please help.
Please, look carefully at the error message:
NameError: undefined local variable or method ` FacebookCrawl' for main:Object
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑
The first giveaway is that you get a NameError for an undefined local variable or method, and not for a constant. The second giveaway is the name that Ruby complains about: it doesn't complain about FacebookCrawl, it complains about FacebookCrawl.
In Ruby, only the Unicode characters U+0020 SPACE and U+0009 CHARACTER TABULATION are treated as whitespace. You have two Chinese U+3000 IDEOGRAPHIC SPACE characters, which Ruby simply treats as part of the name, and since they are not uppercase characters, it treats the name as a local variable or message send.
You should probably turn on visible whitespace in your editor, e.g. this is how your code looks in my editor, making it immediately obvious where the problem is:
Copy the facebook_crawl.rb in app/services folder & restart the server.
This is your business logic, so it should be in services folder & not in the models
So create a services folder as well in the app directory.
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.
I had already ran "$rails generate paperclip pin image" but decided to reinstall it to attempt to resolve "Could Not Run The Identify Command. Please Install ImageMagick." error while uploading image.
Thus went to terminal and ran "$ rails generate paperclip pin image --force" but ran into a problem I cant resolve. Pls help!
Steven-Lims-MacBook-Pro:Pinteresting stevenlim$ rake db:migrate
== AddAttachmentImageToPins: migrating =======================================
-- change_table(:pins)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: image_file_name: ALTER TABLE "pins" ADD "image_file_name" varchar(255)/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `block in execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:360:in `add_column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:454:in `add_column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb:360:in `column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:52:in `block (2 levels) in attachment'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:51:in `each_pair'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:51:in `block in attachment'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:50:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:50:in `attachment'
/Users/stevenlim/Desktop/pinteresting/db/migrate/20140216024257_add_attachment_image_to_pins.rb:4:in `block in up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:334:in `change_table'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:625:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `say_with_time'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:617:in `method_missing'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:383:in `method_missing'
/Users/stevenlim/Desktop/pinteresting/db/migrate/20140216024257_add_attachment_image_to_pins.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:534:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:574:in `exec_migration'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:555:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:554:in `block in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:553:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:709:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:920:in `block in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:764:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:742:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
STATUS
Steven-Lims-MacBook-Pro:Pinteresting stevenlim$ rake db:migrate:status
database: /Users/stevenlim/Desktop/pinteresting/db/development.sqlite3
Status Migration ID Migration Name
--------------------------------------------------
up 20140205132449 Devise create users
up 20140210143217 Create pins
up 20140212145812 Add user id to pins
up 20140215161350 ********** NO FILE **********
down 20140216134900 Add attachment image to pins
ImageMagick is a prerequisite for Paperclip gem. Paperclip would work only if ImageMagick is installed on your system and Paperclip has access to it. Looking at your error "Could Not Run The Identify Command. Please Install ImageMagick." it seems like ImageMagick is not installed on your system. First step is to install it or check if it's installed then in your environment config file, let Paperclip know where to look for ImageMagick by adding ImageMagick path to it.
For eg:
In development mode, you might add this line to config/environments/development.rb
Paperclip.options[:command_path] = write_your_imagemagick_path
Where
You can get ImageMagick path by running which convert
Looking at the second error which you got, it seems like you already ran the migration once before, hence, the paperclip attachment related fields like image_file_name are already created in database table pins. And as you are trying to run that migration again you are getting duplicate column name error.
EDIT:
When you generated the paperclip pin image for the first time, one migration file was created under db/migrations which looking at the error I am assuming that you ran using rake db:migrate which is why you already have Paperclip image related columns in your pins table.
Later when you generated the paperclip pin image for the second time another migration file is created with the same column names which when you run using rake db:migrate is obviously going to yield duplicate column error.
You can just delete this second migration file, you don't need to run it as the columns are already created in database.
BUT if you still want to run the second migration file itself then first do rake db:rollback till the step where you ran the first migration so the image related columns would be removed from database. Then delete the first migration file and run rake db: migrate Which would run the second migration file and create the image related columns for you in the pins table.
I can't post comment (as I must have 50 rep). All you you need to do is delete that number from your schema_migrations table in the database.
#baloo, #user3317140 - Thanks for the help. I managed to solve this after many trial and error and hope this will help others facing same problem.
To delete the Migration ID: 20140215161350 Migration name: ********** NO FILE **********, I went to create 20140215161350_create_nothing.rb with the code class CreateNothing < ActiveRecord::Migration def change end end.
This allows migration name to be found and I thereafter ran rake:db:rollback.
I did another rake:db:rollback for the $ rails generate paperclip pin image.
All clean now. Back to the ImageMagick problem.
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
I'm struggling with this error after I fire the command rake apn:notifications:deliver on the APN on Rails gem that I've installed.
It's barking about the RAILS_ENV variable. I've tried a couple of forks that change RAILS_ENV to Rails.env but I still get the same error. I've posted my issue over on that repo hoping I might get somewhere.
I don't know enough about rails to dig in any further. I'm hoping someone could point me in the right direction so that I can a) better understand what went wrong and b) fix the problem.
I am using bundler and I'm pointing my gem file to the git repo: rake apn:notifications:deliver
air:apnapp azcoov$ rake apn:notifications:deliver --trace
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/version.rb:2: warning: already initialized constant VERSION
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
rake aborted!
uninitialized constant APN::App::RAILS_ENV
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:11:in `cert'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:22:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:32:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `each'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/rails/../tasks/apn.rake:7
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Tasks: TOP => apn:notifications:deliver
Which version of Rails to you use? I just ran into this issue too. My Rails knowledge is not very deep, but it seems like the problem is deprecation of RAILS_* environment variables. I use Rails 3.1.0 and I do NOT have:
RAILS_ROOT/ENV/blah
in my environment. Instead, I have:
Rails.root/env/blah
When I replace RAILS_ENV with Rails.env in app/models/apn/app.rb the problem goes away.
So, is this gem compatible with Rails 3.1.0??? It seems not. Is there a workaround that will allow its use in a Production environment? Maybe define somewhere:
APN::App::RAILS_ENV = Rails.env
But where?
UPDATE:
I got it working with a workaround described by garyfoster here: https://github.com/PRX/apn_on_rails/issues/53.
To summarize, three things:
1) Add this ghetto hack to your config/environment.rb file:
APN::App::RAILS_ENV = Rails.env
2) Insert your certs in the APN::App table. I wrote a one-time rake task for that:
task :init_apn_certs => [:environment] do # NOTE: One-time task...
print "Creating APN::App with certs..."
app = APN::App.create(:apn_dev_cert => Rails.root.join('config', 'apple_push_notification_development.pem').read,
:apn_prod_cert => Rails.root.join('config', 'apple_push_notification_production.pem').read)
puts (app.valid? ? "done" : "failed")
end
3) Write your own rake task that bypasses the APN::App.send_notifications method, as that barfs with another error (something about '/config/apple_push_notification_development.pem' not existing). My code for it:
task :deliver_notifications => [:environment] do
print "Delivering APNs for app ids..."
apps = APN::App.all
apps.each do |app|
app.send_notifications
print app.id.to_s + "..."
end
puts "done."
end
Or, if you have only one app, you can just do this and be done with it:
task :deliver_notifications => [:environment] do
APN::App.first.send_notifications
end
DISCLAIMER: I'm yet to test this on Staging and Production (will do so by the end of the week), but I see no reason why it shouldn't work.