Skip to content

Commit fcef728

Browse files
committed
revert setting NOT NULL constraints in add_timestamps
Commit 3dbedd2 added NOT NULL constraints both to table creation and modification. For creation the new default makes sense, but the generic situation for changing a table is that there exist records. Those records have no creation or modification timestamps, and in the general case you don't even know them, so when updating a table these constraints are not going to work. See a bug report for this use case in rails#3334.
1 parent 447d87c commit fcef728

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ def distinct(columns, order_by)
539539
# ===== Examples
540540
# add_timestamps(:suppliers)
541541
def add_timestamps(table_name)
542-
add_column table_name, :created_at, :datetime, :null => false
543-
add_column table_name, :updated_at, :datetime, :null => false
542+
add_column table_name, :created_at, :datetime
543+
add_column table_name, :updated_at, :datetime
544544
end
545545

546546
# Removes the timestamp columns (created_at and updated_at) from the table definition.

0 commit comments

Comments
 (0)