Understanding Rail Migration Instructions (: null => false)

I am trying to understand the following statement: this is from a rail migration file:

x.datetime "new",     :null => false
x.datetime "update",  :null => false

I understand the first part of both statements (all to the point), but I'm not sure about the zero part

:null => false

Is this basically the expression "if it does not exist, is it false?" The logic seems a little strange, any clarifications on this will be very useful.

+5
source share
3 answers

Edit: I asked a question about the syntax and translation from its originally mentioned CoffeeScript . For the purpose, see Peter Bloom's answer .


I'm not sure what that means :null => false.

=> / Ruby, Hash :null, false. : Object CoffeeScript/JavaScript - { null: false }.

/ Ruby.

, CoffeeScript/JavaScript String , Ruby - "null" (cs/js) :null (rb).

, CoffeeScript :

x.datetime "new",     null: false
x.datetime "update",  null: false

JavaScript :

x.datetime("new",    { null: false });
x.datetime("update", { null: false });
+2

:null => false Rails NULL. :default => 0, "0" (a), NULL (b) . (, "0" NULL - .)

+19

-, x t, .

t create_table ActiveRecord::ConnectionAdapters::TableDefinition.

t.datetime "new",    :null => false
t.datetime "update", :null => false

t.column("new", :datetime, { :null => false })
t.column("update", :datetime, { :null => false })

options column.

According to the documentation, one of these parameters is :nullone that enables or disables NULL values โ€‹โ€‹in a column.

So, in the end it :null => falsewill mean "Do not allow NULL values โ€‹โ€‹in a new column or update."

+2
source

All Articles