Trying to change a column to "null: true" is not being reflected in schema after migration

activerecord, ruby-on-rails

Solution

`null: true` is the default behavior. You will never see it in your schema, you will see either `null: false` or nothing.

Problem

I have a column/foreign key, `resolver_id`, that I want to be able to have null values (ie: Rails Migration to make a column null => true). Let's say I have the following line in my migration: ``` def change_column_null :bugs, :resolver_id, true end ``` However, after running a successful migration (ie, generate the migration and run `rails db:migrate`), the schema remains unchanged, besides the version number: `t.integer "resolver_id"` whereas I am expecting: `t.integer "resolver_id" , null: true` Is there something I'm missing? I've also tried using just `change_column` like so: `change_column :bugs, :resolver_id, :integer, null: true` However, this is still not reflected in the schema. The `rails g migration` and `db:migrate` work just fine, and the version number in the schema matches the latest migration. For reference, here is my schema: ``` ActiveRecord::Schema.define(version: 20170502203934) do create_table "bugs", force: :cascade do |t| t.string "name" t.text "error_msg" t.text "description" t.text "causes" t.boolean "resolved" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "user_id" t.integer "resolver_id" t.index ["resolver_id"], name: "index_bugs_on_resolver_id" t.index ["user_id"], name: "index_bugs_on_user_id" end create_table "users", force: :cascade do |t| t.string "username" t.string "first_name" t.string "last_name" t.string "email" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "password_digest" t.index ["email"], name: "index_users_on_email", unique: true t.index ["username"], name: "index_users_on_username", unique: true end end ``` If relevant, the `resolver_id` foreign key is a reference a User model, ie: ``` class Bug < ApplicationRecord # Associations belongs_to :user belongs_to :resolver, class_name: 'User' end ```

Original source

Related problems