3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntu16.04LTSでNetCommons3のインストールに失敗する問題の対処法

Last updated at Posted at 2017-07-27

環境

  • OS: Ubuntu 16.04 LTS
  • Webサーバ: Apache 2.4 (2.4.18-2ubuntu3.3)
  • PHP: PHP 7.0 (v7.0.18-0ubuntu0.16.04.1) + mod_php
  • DB: MySQL 5.7 (5.7.19-0ubuntu0.16.04.1)
  • NetCommons: NetCommons-3.1.3

現象

  • NetCommons3 をインストールする際に、エラーが発生し、インストールできない。
  • /var/www/html/app/tmp/logs/error.logを確認すると、以下のログが出力されている。
2017-07-27 04:45:08 Error: PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2017-03-22T18:18:22+00:00' for column 'commited' at row 1 in /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php:470
Stack trace:
#0 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php(470): PDOStatement->execute(Array)
#1 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php(436): DboSource->_execute('INSERT INTO `nc...', Array)
#2 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php(1090): DboSource->execute('INSERT INTO `nc...')
#3 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Model.php(1940): DboSource->create(Object(Plugin), Array, Array)
#4 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Model.php(1758): Model->_doSave(Array, Array)
#5 /var/www/html/app/Plugin/PluginManager/Model/Behavior/PluginBehavior.php(345): Model->save(Array)
#6 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/BehaviorCollection.php(238): PluginBehavior->updateVersion(Object(Plugin), Array)
#7 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Model.php(829): BehaviorCollection->dispatchMethod(Object(Plugin), Array, Array)
#8 /var/www/html/app/Plugin/PluginManager/Model/Behavior/PluginComposerBehavior.php(143): Model->__call('updateVersion', Array)
#9 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/BehaviorCollection.php(238): PluginComposerBehavior->updateVersionByComposer(Object(Plugin))
#10 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Model/Model.php(829): BehaviorCollection->dispatchMethod(Object(Plugin), Array, Array)
#11 /var/www/html/app/Plugin/Install/Utility/InstallUtil.php(620): Model->__call('updateVersionBy...', Array)
#12 /var/www/html/app/Plugin/Install/Controller/InstallController.php(193): InstallUtil->installMigrations('master', Array)
#13 [internal function]: InstallController->init_db()
#14 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Controller/Controller.php(491): ReflectionMethod->invokeArgs(Object(InstallController), Array)
#15 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Routing/Dispatcher.php(193): Controller->invokeAction(Object(CakeRequest))
#16 /var/www/html/vendors/cakephp/cakephp/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(InstallController), Object(CakeRequest))
#17 /var/www/html/app/webroot/index.php(106): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))

原因

MySQL5.6より、以下の設定がデフォルトで有効になっているため。

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

NetCommons3 のインストール時には、マイグレーション処理によりDB上へのテーブル作成等が行われますが、その際にMySQLのdatetime型の書式に合わない値が追加されます(追加されようとします)。STRICT_TRANS_TABLESが無効な場合はエラーとならず処理は続行されますが、STRICT_TRANS_TABLESが有効な場合、エラーが発生してインストールが中断します。

STRICT_TRANS_TABLE とは

厳密SQLモードと呼ばれる状態です。
本件は、厳密モードが有効であったため、以下の制約が生じてエラーになりました。

https://dev.mysql.com/doc/refman/5.6/ja/constraint-invalid-data.html より

MySQL では、特定の不正なデータ値を、DATE カラムと DATETIME カラムに格納できます ('2000-02-31' や '2000-02-00' など)。この場合、アプリケーションが厳密 SQL モードを有効にしていなければ、これらを格納する前に日付を検証するのはアプリケーションに任されます。MySQL が日付値を格納し、ちょうど同じ値を検索できる場合、MySQL は与えられたとおりに格納します。日付が完全に不正な場合 (サーバーの格納能力を超えている場合) は、代わりに特殊な「ゼロ」日付値である '0000-00-00' がカラムに格納されます。

対応方法

NO_STRICT_TRANS_TABLES とすることで、この問題を回避することができます。(/etc/mysql/mysql.conf.d/mysqld.cnfに記述します)

sql_mode=NO_ENGINE_SUBSTITUTION,NO_STRICT_TRANS_TABLES
3
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?