Skip to content

Instantly share code, notes, and snippets.

@jimmiw
Created June 16, 2010 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmiw/441240 to your computer and use it in GitHub Desktop.
Save jimmiw/441240 to your computer and use it in GitHub Desktop.
created_at datetime default now()
# If you need to add a created_at field in your database
# that inserts "now()" when the insert statement is run, you
# can use the following script.
# It uses timestamps, but removes the "on update" for the
# created_at column, but keeps it on the updated_at (which
# needs to update at every change).
#
# got this snippet here:
# http://bugs.mysql.com/bug.php?id=27645
# (search for: "[7 Oct 2009 4:25] Diego Medina")
created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment