bobdenotter / seo

Bolt SEO extension
https://bobdenotter.github.io/seo/
MIT License
49 stars 34 forks source link

Database exception when adding SEO type field to existing database #16

Closed Pinpickle closed 8 years ago

Pinpickle commented 8 years ago

In Bolt v2.2.16, when I add a field of type SEO when a database (SQLite) is already present, I get the following exception:

Doctrine\DBAL\Exception\DriverException thrown with message "An exception occurred while executing 'ALTER TABLE bolt_resources ADD COLUMN seo CLOB NOT NULL':

SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL"

Stacktrace:
#18 Doctrine\DBAL\Exception\DriverException in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php:85
#17 Doctrine\DBAL\Driver\AbstractSQLiteDriver:convertException in /vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:116
#16 Doctrine\DBAL\DBALException:driverExceptionDuringQuery in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:996
#15 Bolt\Controllers\Backend:dbUpdate in <#unknown>:0
#14 Doctrine\DBAL\Driver\PDOException in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:59
#13 Bolt\Controllers\Backend:dbUpdate in <#unknown>:0
#12 PDOException in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:57
#11 PDO:exec in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:57
#10 Doctrine\DBAL\Driver\PDOConnection:exec in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:993
#9 Doctrine\DBAL\Connection:executeUpdate in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php:1017
#8 Doctrine\DBAL\Schema\AbstractSchemaManager:_execSql in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php:626
#7 Doctrine\DBAL\Schema\AbstractSchemaManager:alterTable in /vendor/bolt/bolt/src/Database/IntegrityChecker.php:306
#6 Bolt\Database\IntegrityChecker:repairTables in /vendor/bolt/bolt/src/Controllers/Backend.php:220
#5 Bolt\Controllers\Backend:dbUpdate in <#unknown>:0
#4 call_user_func_array in /vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:145
#3 Symfony\Component\HttpKernel\HttpKernel:handleRaw in /vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:66
#2 Symfony\Component\HttpKernel\HttpKernel:handle in /vendor/silex/silex/src/Silex/Application.php:547
#1 Silex\Application:handle in /vendor/silex/silex/src/Silex/Application.php:524
#0 Silex\Application:run in /public/index.php:35

On the latest SEO extension version

ScreamZ commented 8 years ago

Probable solution is to make it nullable, or make something updating fields... :/

MichaelMackus commented 8 years ago

Yea I noticed this on a recent bolt site. Changing sqlite to mysql fixes this (as well as giving other advantages of mysql), but may not be practical for some. I believe sqlite is very particular on setting of default values, while mysql seems to figure them out itself.

EDIT: You might be able to bandaid by executing the SQL directly onto the sqlite database (using the command line). Perhaps something like this?

ALTER TABLE bolt_resources ADD COLUMN seo CLOB NOT NULL DEFAULT ''

or even just

ALTER TABLE bolt_resources ADD COLUMN seo CLOB