On Migration: undefined method `to_sym' for nil:NilClass

后端 未结 9 1903
日久生厌
日久生厌 2020-12-10 12:27

I\'m running Rails 3.0.3 and I accidentally made a typo in my migration: I created a migration that creates a new column with a type of boolen (it should have b

9条回答
  •  佛祖请我去吃肉
    2020-12-10 12:34

    The error:

    undefined method `to_sym' for nil:NilClass
    

    is caused because Rails doesn't know the type of the column. Why doesn't it know the type? Because the type isn't in the schema.rb file. In my case I looked for the table with the problem and found:

    # Could not dump table "simulation_results" because of following StandardError 
    # Unknown type 'real' for column 'elevator_kbtu_site'
    

    I changed the original migration to use float instead of real and the problem went away when I dropped the database and rebuilt it from scratch.

    In my case I only use SQLite for test and development where dropping the database and rebuilding it from scratch is a regular operation. We use a different database which doesn't have this issue in production, so changing the older migration works for me.

提交回复
热议问题