Skip to content

Change the default null value for timestamps #16481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2014

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Aug 12, 2014

As per discussion, this changes the model generators to specify
null: false for timestamp columns. A warning is now emitted if
timestamps is called without a null option specified, so we can
safely change the behavior when no option is specified in Rails 5.

As per discussion, this changes the model generators to specify
`null: false` for timestamp columns. A warning is now emitted if
`timestamps` is called without a `null` option specified, so we can
safely change the behavior when no option is specified in Rails 5.
@jeremy
Copy link
Member

jeremy commented Aug 12, 2014

Not sure how this can be safe unless old migrations are updated as well? They'll be implicitly null: true, but will generate null: false after the app is upgraded to Rails 5.

@sgrif
Copy link
Contributor Author

sgrif commented Aug 12, 2014

That's the goal behind the deprecation warning if it is unspecified, users will need to specify null: true if they would like to keep that behavior, and will receive a deprecation warning until they specify one way or the other.

@jeremy
Copy link
Member

jeremy commented Aug 12, 2014

The deprecation warning will come too late though, after the migration already ran on the production db.

@sgrif
Copy link
Contributor Author

sgrif commented Aug 12, 2014

The warning would also appear any time anyone did anything related to schema.rb, including running tests after a new migration is created.

dhh added a commit that referenced this pull request Aug 18, 2014
Change the default `null` value for timestamps
@dhh dhh merged commit 7ee0550 into rails:master Aug 18, 2014
@prathamesh-sonpatki
Copy link
Member

@sgrif @jeremy Should this be mentioned in upgrade guide?

@jschroeder9000
Copy link

This deprecation only pertains to the timestamps method that creates the created_at and updated_at columns, right? I had a migration that had both t.timestamps and t.timestamp :column_name in it spit this out at me and since the deprecation message says #timestamp (note lack of s) it was a bit confusing.

ggiraldez added a commit to instedd/resourcemap that referenced this pull request Mar 29, 2016
- Use unscoped when referring to Site to remove the deleted_at column in
  SQL queries built by ActiveRecord.
- Add :null => false to all timestamps definitions. Default changed
  from Rails 3.2 to 4.0. See rails/rails#16481
@sgrif sgrif deleted the sg-change-default-timestamps branch March 14, 2018 20:53
dazralsky pushed a commit to dazralsky/closure_tree that referenced this pull request Aug 21, 2023
Fix Rails 5 deprecation warning for not explicitly setting the null option
for timestamps. Also moved other timestamps to use timestamps method

This deprecation warning was introduced in rails/rails#16481
christophervojick119 pushed a commit to christophervojick119/closure_tree that referenced this pull request Dec 19, 2024
Fix Rails 5 deprecation warning for not explicitly setting the null option
for timestamps. Also moved other timestamps to use timestamps method

This deprecation warning was introduced in rails/rails#16481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants