craft-carbon-tracker icon indicating copy to clipboard operation
craft-carbon-tracker copied to clipboard

Postgres Error during Install

Open vardumper opened this issue 1 year ago • 3 comments

This happened on Craft 5.0.3, PHP 8.3, Postgres 16 on DDEV

Copy Stacktrace Search Stackoverflow Search Google Exception
Migration Error – craft\errors\MigrationException

An error occurred while executing the "statikbe\carbontracker\migrations\Install migration: SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "green" is of type boolean but default expression is of type integer
HINT: You will need to rewrite or cast the expression.
The SQL being executed was: CREATE TABLE "carbontracker_stats" (
"id" serial NOT NULL PRIMARY KEY,
"entryId" integer NOT NULL,
"siteId" integer NOT NULL,
"url" varchar(255) NOT NULL,
"green" boolean DEFAULT 0,
"bytes" integer,
"cleanerThan" double precision DEFAULT 0,
"rating" varchar(2),
"dateCreated" timestamp(0) NOT NULL,
"dateUpdated" timestamp(0) NOT NULL,
"dateDeleted" timestamp(0) NULL DEFAULT NULL,
"uid" char(36) NOT NULL DEFAULT '0'
)
↵
Caused by: Database Exception – [yii\db\Exception](https://www.yiiframework.com/doc-2.0/yii-db-exception.html)

SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "green" is of type boolean but default expression is of type integer
HINT: You will need to rewrite or cast the expression.
The SQL being executed was: CREATE TABLE "carbontracker_stats" (
"id" serial NOT NULL PRIMARY KEY,
"entryId" integer NOT NULL,
"siteId" integer NOT NULL,
"url" varchar(255) NOT NULL,
"green" boolean DEFAULT 0,
"bytes" integer,
"cleanerThan" double precision DEFAULT 0,
"rating" varchar(2),
"dateCreated" timestamp(0) NOT NULL,
"dateUpdated" timestamp(0) NOT NULL,
"dateDeleted" timestamp(0) NULL DEFAULT NULL,
"uid" char(36) NOT NULL DEFAULT '0'
)

in /var/www/html/vendor/yiisoft/yii2/db/Schema.php at line 676
Error Info: Array
(
    [0] => 42804
    [1] => 7
    [2] => ERROR:  column "green" is of type boolean but default expression is of type integer
HINT:  You will need to rewrite or cast the expression.
)
↵
Caused by: PDOException

SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "green" is of type boolean but default expression is of type integer
HINT: You will need to rewrite or cast the expression.

in /var/www/html/vendor/yiisoft/yii2/db/Command.php at line 1302

Hope this is useful.

vardumper avatar Apr 10 '24 11:04 vardumper

I don't have much postgres expierence but I assume this line is the problem:

https://github.com/statikbe/craft-carbon-tracker/blob/99307676eb925d5b922876cd00a366e6fe515a9b/src/migrations/Install.php#L20

I'll see if changing the default value to false fixes the issue.

janhenckens avatar Apr 10 '24 12:04 janhenckens

Should be fixed in 5.0.1, @vardumper can you give that a try? Thanks!

janhenckens avatar Apr 10 '24 12:04 janhenckens

~Sure thing, I'll ping you here later on.~ Yep, I could now install the plugin. Thanks!

vardumper avatar Apr 11 '24 09:04 vardumper