Mike.Whitehead
Mike.Whitehead

Reputation: 818

Rails migration error - table not showing in schema.rb

One of my model tables (Event) is not showing in the schema.rb file and in its place there is this message -

# Could not dump table "events" because of following NoMethodError
#   undefined method `[]' for nil:NilClass

The last migration that was succesful was as follows -

class RemoveOrganiserDescriptionFromEvents < ActiveRecord::Migration
  def change
    remove_column :events, :organiser_description, :text
  end
end

Which was changed to this -

class AddOrganiserProfileToEvents < ActiveRecord::Migration
  def change
    add_column :events, :organiser_profile, :url
  end
end

I'm pretty sure its gone 'wonky' because the attribute shouldn't be a url it should be a string. However, when I try to perform other migrations it doesn't work. I get the following error in my terminal when I try and perform a rake db:migrate -

undefined method to_sym' for nil:NilClass Did you mean? to_s/Users/Michael/MWCoding/MamaKnows/mama_knows/db/migrate/20160415123947_remove_events_organiser_profile.rb:3:inchange' NoMethodError: undefined method `to_sym' for nil:NilClass Did you mean? to_s

In my migration files this was my code -

def change
   change_column :events, :organiser_profile :string

end

def up
  change_column :events, :organiser_profile, :string
end

def down
  change_column :events, :organiser_profile, :url
end

I've also tried to remove the column completely in an attempt to then replace it with the correct version but to no avail. All impending help would be appreciated.

Upvotes: 2

Views: 2233

Answers (2)

Moe
Moe

Reputation: 11

I was able to fix this by dropping the migrations and re-migrating:

rake db:drop:all

then

rake db:migrate

Upvotes: 1

Kalman
Kalman

Reputation: 8121

add_column :events, :organiser_profile, :url

does not make sense. See the documentation for add_column method here. The parameters are table, column name and column type. :url is not a valid type. Valid types are listed here

Upvotes: 0

Related Questions