Rails migration add a null: false column with an initial value that's not an ongoing default

Viewed 588

I have this migration which I don't like:

    add_column :employers, :address_line_1, :string
    add_column :employers, :address_city, :string
    add_column :employers, :address_postcode, :string

    change_column_null :employers, :address_line_1, false, '123 default street'
    change_column_null :employers, :address_city, false, 'Default City'
    change_column_null :employers, :address_postcode, false, '123456'

Making the add_column lines have null: false is invalid since I have existing records, and I don't want any default value (except for at the time of this migration).

Can columns be added with an intial (but not default) value in a single line of code?

1 Answers
Related