New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4.2 - PopulateCountriesandStates Migration Error #84

tamizahmed opened this Issue Sep 21, 2015 · 3 comments


None yet
4 participants

tamizahmed commented Sep 21, 2015

Hi there - I'm trying to install piggybak in my Rails 4.2.2. app, but the installation gets stalled during the migrations (details below).

I've read through a number of issues that were related to the countries migration, but none seemed to be this particular problem. Please help!

== 20150921001302 PopulateCountriesAndStates: migrating =======================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method []' for #<ISO3166::Country:0x007f91c4f5eff8>/.../db/migrate/20150921001302_populate_countries_and_states.piggybak.rb:14:inblock in up'


This comment has been minimized.

AToner commented Sep 25, 2015

Looks like the countries gem has had a big change that might be causing this...

specifically lib/countries/country.rb

commit here ... hexorx/countries@a3cbddc


This comment has been minimized.

b3ccio commented Oct 29, 2015

Here's my updated migration with alpha2 replacing abbr. Also had to switch the abbr and name variables for state. It was backwards for me.

ISO3166::Country.all.each do |country_array|
  name =
  abbr = country_array.alpha2

  country = Piggybak::Country.create :name => name, :abbr => abbr

  iso3166_country =
  iso3166_country.states.each do |key, value|
    abbr = key
    name = value["name"]
    Piggybak::State.create! :name => name, :abbr => abbr, :country => country

This comment has been minimized.

marcog commented Jan 15, 2016

I fixed the problem by changing the migration to: do |country_array|
  name = country_array[0]
  abbr = country_array[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment