Rails 4: schema.db shows “Could not dump table ”events“ because of following NoMethodError# undefined method `[]' for nil:NilClass”

前端 未结 2 1643
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 13:28

I\'ve been working on a Rails 4.0 application with sqlite (default for Rails development environment) for events (hackathons) which has a parent model, Event, for which ther

相关标签:
2条回答
  • 2020-12-24 14:16

    Just in case this helps someone. I was doing this on a sqlite dev db, and as mentioned above, it was likely in a wonky state from all my experimental migrations. By deleting the sqlite file, recreating and running all the migrations, it is now fine.

    0 讨论(0)
  • 2020-12-24 14:31

    I think your last migration is wrong. I would change it to this:

    class AddEventRefToPressBlurbs < ActiveRecord::Migration
      def change
        add_reference :press_blurb, :event
      end
    end
    

    Unfortunately, your database is likely in a wonky state because it has an invalid column type (i.e. there is no 'reference' column type, but sqlite made it anyway). Hopefully, it's just a development database so you can just delete it and start fresh.

    0 讨论(0)
提交回复
热议问题