1

I'm relatively new to rails - I've been coding for 4 months - and I'm having a hell of a time installing the rapns gem for Apple push notifications into a Rails app serving as a back-end server for an iOS app.

I'm using ruby 1.9.3p327, rails 3.2.13, and rapns 3.3.1.

I successfully ran "rails g rapns" from these instructions then when I run "rake db:migrate" I get the error below when rails tried to run the add_gcm migration file:

==  AddGcm: migrating =========================================================
-- add_column(:rapns_notifications, :type, :string, {:null=>true})
   -> 0.0385s
-- add_column(:rapns_apps, :type, :string, {:null=>true})
   -> 0.0247s
-- change_column(:rapns_notifications, :type, :string, {:null=>false})
   -> 0.0456s
-- change_column(:rapns_apps, :type, :string, {:null=>false})
   -> 0.0222s
-- change_column(:rapns_notifications, :device_token, :string, {:null=>true, :limit=>64})
   -> 0.0372s
-- change_column(:rapns_notifications, :expiry, :integer, {:null=>true, :default=>86400})
   -> 0.0319s
-- change_column(:rapns_apps, :environment, :string, {:null=>true})
   -> 0.0213s
-- change_column(:rapns_apps, :certificate, :text)
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: BLOB/TEXT column 'certificate' can't have a default value: ALTER TABLE `rapns_apps` CHANGE `certificate` `certificate` text DEFAULT '' NOT NULL/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `block in execute'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:480:in `change_column'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in `block in method_missing'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `block in say_with_time'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `say_with_time'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:458:in `method_missing'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:334:in `method_missing'
/Users/Greg/Camboo-Server/db/migrate/20130620184555_add_gcm.rb:25:in `up'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:370:in `up'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block in migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in `migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:in `migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:777:in `call'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:777:in `ddl_transaction'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in `block in migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `each'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:in `up'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in `migrate'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
/Users/Greg/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'

Here is what I've tried:

  • I removed ":null => true" from both the up and down portions of the migration file. When I run "rake db:migrate" now I got this error: Mysql2::Error: Duplicate column name 'type': ALTER TABLE rapns_notifications ADD type (I can provide trace if needed). Based on this Github issue.
  • Once that worked, I commented out both `add_column :rapns_notifications, :type, :string, :null => true

    add_column :rapns_apps, :type, :string, :null => true` because both were giving me "duplicate column" errors. Loosely based on this SO answer

After performing the above steps, I got the migrations to successfully work. I'm going to continue forward and see if I can install Rapns without those columns and the default for :certificate

Any ideas what I'm doing wrong? Is this an issue with migrations and rollbacks that I just don't understand? Maybe a Mysql2 bug that I can't get around. Or something else entirely.

I'll edit my question as I continue forward.

Thank you for the help, SO'ers! You guys rock.

EDIT (6/20 15:44): I tried to create a new Rapns app via rails console and found that the add_gcm migration file isn't migrating fully. In my schema, the rapns_app still has a :key attribute, which has been changed to :name in rapns 3.x to support gcm. So, without :name I can't create an apns_app. Why isn't the migration file running properly?

EDIT (6/24): Apparently this is a bug with rapns. Working with the maintainer to get it solved. Thanks SO.

Community
  • 1
  • 1
gregb
  • 732
  • 5
  • 9

0 Answers0