Skip to content
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

Migration fail: Invalid default value for 'created_at' #9

TrueXakeP opened this Issue Oct 2, 2016 · 2 comments


None yet
2 participants
Copy link

commented Oct 2, 2016

php 7.0.8 x64
mysql 5.7.11 x64
windows 8.1 x64

Setting 0 or "0000-00-00" does not help

$ ./yii migrate
Yii Migration Tool (based on Yii v2.0.10-dev)

Total 1 new migration to be applied:

Apply the above migration? (yes|no) [no]:y
*** applying m150429_155009_create_page_table
    > create table {{%page}} ...Exception 'yii\db\Exception' with message 'SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at'
The SQL being executed was: CREATE TABLE `page` (
        `title` varchar(255) NOT NULL,
        `alias` varchar(255) NOT NULL,
        `published` tinyint(1) DEFAULT 1,
        `content` text,
        `title_browser` varchar(255),
        `meta_keywords` varchar(200),
        `meta_description` varchar(160),
        `created_at` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00",
        `updated_at` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00"

in C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\db\Schema.php:631

Error Info:
    [0] => 42000
    [1] => 1067
    [2] => Invalid default value for 'created_at'

Stack trace:
#0 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\db\Command.php(854): yii\db\Schema->convertException(Object(PDOException), 'CREATE TABLE `p...')
#1 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\db\Migration.php(261): yii\db\Command->execute()
#2 C:\Tools\OpenServer\domains\yii2-app-advanced\console\migrations\m150429_155009_create_page_table.php(35): yii\db\Migration->createTable('{{%page}}', Array)
#3 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(651): m150429_155009_create_page_table->up()
#4 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(163): yii\console\controllers\BaseMigrateController->migrateUp('m150429_155009_
#5 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#6 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
#7 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#8 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\Controller.php(127): yii\base\Controller->runAction('', Array)
#9 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\Module.php(454): yii\console\Controller->runAction('', Array)
#10 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
#11 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
#12 C:\Tools\OpenServer\domains\yii2-app-advanced\vendor\yiisoft\yii2\base\Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))
#13 C:\Tools\OpenServer\domains\yii2-app-advanced\yii(27): yii\base\Application->run()
#14 {main}

Finally I got it working by using DEFAULT CURRENT_TIMESTAMP for created_at and DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP for updated_at.


This comment has been minimized.

Copy link

commented Feb 25, 2018

Fixed in 1.3.0. :D Sorry for my terrible slowness.

@bupy7 bupy7 closed this Feb 25, 2018


This comment has been minimized.

Copy link

commented Feb 26, 2018

Oh, do you really understand what I meant by this message with a terrible lack of information? 😄 Sorry for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.