Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

migration does'nt work correctly for timestamp with default null.

I'm using phalcon devtools for DB's migration.

so, I wanted to create a table that have deleted_at column as the below.

     new Column(
                        'deleted_at',
                        [
                            'type' => Column::TYPE_TIMESTAMP,
                            'default' => null,
                            'notNull' => false,
                            'after' => 'updated_at'
                        ]
                    )

I assumed that deleted_at column is TYPE_TIMESTAMP and default value is null .But, an error occured.

ERROR: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'deleted_at'

so, I deleted 'default' => null as the below.

     new Column(
                        'deleted_at',
                        [
                            'type' => Column::TYPE_TIMESTAMP,
                            'notNull' => false,
                            'after' => 'updated_at'
                        ]
                    )

But, The results are the same.

Please help me for creating TIMESTAMPcolumn that has default value NULL.



973
edited Aug '18

I referred this similar discussion.

But, not work.

                    new Column(
                        'deleted_at',
                        [
                            'type' => Column::TYPE_TIMESTAMP,
                            'notNull' => false,
                            'default' => new RawValue('default'),
                            'after' => 'updated_at'
                        ]
                    )
ERROR: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'deleted_at'

My phalcon version is as the below.


bash-4.2# phalcon --version

Phalcon DevTools (3.4.0)

Environment:
  OS: Linux f223c77b0fed 4.9.60-linuxkit-aufs #1 SMP Mon Nov 6 16:00:12 UTC 2017 x86_64
  PHP Version: 7.2.5
  PHP SAPI: cli
  PHP Bin: /usr/bin/php
  PHP Extension Dir: /usr/lib64/php/modules
  PHP Bin Dir: /usr/bin
  Loaded PHP config: /etc/php.ini
Versions:
  Phalcon DevTools Version: 3.4.0
  Phalcon Version: 3.4.1
  AdminLTE Version: 2.3.6

Please help me...



1.4k
Accepted
answer

'default' => new RawValue('CURRENT_TIMESTAMP')