Phinx: Sanity check for addTimestamps() function

Created on 14 Apr 2015  Â·  6Comments  Â·  Source: cakephp/phinx

I tried using the addTimestamps() function today and what happened seemed to me to be incorrect behavior. When doing a DESC on my mysql table I got back the following:

| Field        | Type         | Null | Key | Default           | Extra                       |
+--------------+--------------+------+-----+-------------------+-----------------------------+
| created_at   | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| updated_at   | timestamp    | YES  |     | NULL              |                             |
+--------------+--------------+------+-----+-------------------+-----------------------------+

I would expect the Extra field of 'on update CURRENT_TIMESTAMP' to be attached to the updated_at field not the created_at field. I don't know that this is incorrect behavior, but it is not what I would have expected to occur, so, I figured I would at least point it out. If you could please let me know if this is the intended behavior which Phinx wants or if this is an actual issue.

Thanks.

Most helpful comment

'update' => 'CURRENT_TIMESTAMP' is needed to be added to docs.

All 6 comments

I had the same behavior, actually phinx adds the on update CURRENT_TIMESTAMP EXTRA to the first timestamp column.

So you can hack the system by inverting your created_at with updated_at column!

But this bug needs to be corrected...

Or, you can use column options:
http://phinx.readthedocs.org/en/latest/migrations.html?highlight=option#valid-column-options

For example:

$myTable = $this->table('myTable');
$myTable
    ->addColumn('created_at', 'timestamp',
        array('default' => '0000-00-00 00:00:00', 'update' => ''))
    ->addColumn('updated_at', 'timestamp',
        array('default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP'))
    ->save();

'update' => 'CURRENT_TIMESTAMP' is needed to be added to docs.

What if I just want to use default as 'CURRENT_TIMESTAMP' but do NOT want to update?
What values can 'update' take ?

What if I just want to use default as 'CURRENT_TIMESTAMP' but do NOT want to update?
What values can 'update' take ?

Hi, im new to phinx,but from what i've been reading from the docs you could put the value on update has 'NO_ACTION'

'update' =>'NO_ACTION'

http://docs.phinx.org/en/latest/migrations.html?highlight=NO_ACTION

‘SET_NULL’, ‘NO_ACTION’, ‘CASCADE’ and ‘RESTRICT’ are actions for ON UPDATE and ON DELETE on foreign key constraints and are unrelated to timestamps.

update option for timestamps can only be 'CURRENT_TIMESTAMP' or nothing at all.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aimfeld picture aimfeld  Â·  23Comments

robmorgan picture robmorgan  Â·  20Comments

ahmarov picture ahmarov  Â·  27Comments

wpillar picture wpillar  Â·  97Comments

jeremylivingston picture jeremylivingston  Â·  20Comments