There is such a migration

class AddApplicationToNotificationEvent < ActiveRecord::Migration def change add_column :notification_events, :application, :string, :null => true end end 

But after it in schema.rb there is no :null => true

 create_table "notification_events", :force => true do |t| t.integer "subject_id" t.string "subject_type" t.integer "eventable_id" t.string "eventable_type" t.string "service" t.string "kind" t.text "data" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.boolean "read", :default => false, :null => false t.string "application" end 

And in the database there. Why?

  • judging by the instructions :null => false ,: :null => true assumed by default - etki

2 answers 2

Generally speaking, the answer to this question is because the Rails developers decided so .

Why did they decide that? You can ask them, of course.

But most likely, because SQL works in the same way (or rather, the DDL of databases that support it), this is how modern RDBMSs work, under the pressure of well-known standards. Without an explicit indication, they consider that a column of any type may have no value, and the reverse is explicitly indicated using NOT NULL . So it is here.

    By default, null is allowed. Therefore, this parameter is not displayed in the diagram. Now, if it is not allowed, then the processing code null is taken into account here.