anchorcms/anchor-cms

Database errors (1138 Invalid use of NULL value) after fresh install

Closed this issue · 2 comments

Summary

After a fresh install, i receive this error when entering the site:

Database Error: SQLSTATE[22004]: Null value not allowed: 1138 Invalid use of NULL value
SQL: ALTER TABLE comments CHANGE date date datetime NOT NULL AFTER status
The error has been logged in /anchor/errors.log

Expected Behaviour

  • the main page or admin panel

Actual Behaviour

  • After a fresh install (clean database too) I receive the stated SQL error.

Context details (if applicable)

  • Anchor version: 0.12.3
  • Server setup:
    PHP built-in server, version 5.6.30
    MYSQL Ver 14.14 Distrib 5.7.18, for osx10.12 (x86_64) using EditLine wrapper
  • URL root page (/).

After changed anchor/migrations/21_alter_comments_date.php#L11 from:

$sql = 'ALTER TABLE `' . $table . '` CHANGE `date` `date` datetime NOT NULL AFTER `status`';

to:

$sql = 'ALTER TABLE `' . $table . '` CHANGE `date` `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `status`';

and anchor/migrations/61_alter_posts_created.php#L11 from:

$sql = 'ALTER TABLE `' . $table . '` CHANGE `created` `created` datetime NOT NULL AFTER `js`';

to:

$sql = 'ALTER TABLE `' . $table . '` CHANGE `created` `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `js`';

Seems to have fixed these errors. It works now.

@7anshuai Cheers for this! Submit a PR so we can have this merged right away!