Reputation: 818
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:in
change'
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
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