How to solve “Cannot add a NOT NULL column with default value NULL” in SQLite3?

前端 未结 4 1748
时光说笑
时光说笑 2020-11-28 06:43

I am getting the following error while trying to add a NOT NULL column to an existing table. Why is it happening ?. I tried rake db:reset thinking that the existing records

4条回答
  •  囚心锁ツ
    2020-11-28 07:41

    The following migration worked for me in Rails 6:

    class AddDivisionToProfile < ActiveRecord::Migration[6.0]
      def change
        add_reference :profiles, :division, foreign_key: true
        change_column_null :profiles, :division_id, false
      end
    end
    

    Note :division in the first line and :division_id in the second

    API Doc for change_column_null

提交回复
热议问题