Question: Consider the table creation script below:

```
create_table :foo do |t|
  t.datetime :starts_at, :null => false
end

```

Is it's possible to set the default value as the current time?

I am trying to find a DB independent equivalent in rails for the SQL column definitions given below:

**Oracle Syntax**

```
start_at DATE DEFAULT SYSDATE() 

```

**MySQL Syntax**

```
start_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

```

OR

```
start_at DATETIME DEFAULT NOW()

```

Answer: 
This is supported now in Rails 5. 

Here is a sample migration:

```
class CreatePosts < ActiveRecord::Migration[5.0]
  def change
    create_table :posts do |t|
      t.datetime :modified_at, default: -> { 'CURRENT_TIMESTAMP' }
      t.timestamps
    end
  end 
end

```

See discussion at <https://github.com/rails/rails/issues/27077> and answer there by prathamesh-sonpatki
In the answer given by @szymon-lipiński (Szymon Lipiński), the execute method didn't work for me. It was throwing a MySQL syntax error.

The MySQL syntax which worked for me is this.

```
execute "ALTER TABLE mytable CHANGE `column_name` `column_name` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"

```

So to set the default value for a datetime column in migration script can be done as follows:

```
def up
  create_table :foo do |t|
    t.datetime :starts_at, :null => false
  end

  execute "ALTER TABLE `foo` CHANGE `starts_at` `starts_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"
end

```