Cms: MigrationException when installing Craft on Heroku with Postgres

Created on 24 Sep 2019  路  5Comments  路  Source: craftcms/cms

Description

Deploying on Heroku and when I navigate to /admin/install, I get the following on my CLI:

Exception 'craft\errors\MigrationException' with message 'An error occurred while executing the "craft\migrations\Install migration: SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "ORDER"
LINE 58: ORDER BY
         ^
The SQL being executed was: SELECT
    d.nspname AS table_schema,
    c.relname AS table_name,
    a.attname AS column_name,
    COALESCE(td.typname, tb.typname, t.typname) AS data_type,
    COALESCE(td.typtype, tb.typtype, t.typtype) AS type_type,
    a.attlen AS character_maximum_length,
    pg_catalog.col_description(c.oid, a.attnum) AS column_comment,
    a.atttypmod AS modifier,
    a.attnotnull = false AS is_nullable,
    CAST(pg_get_expr(ad.adbin, ad.adrelid) AS varchar) AS column_default,
    coalesce(pg_get_expr(ad.adbin, ad.adrelid) ~ 'nextval',false) AS is_autoinc,
    CASE WHEN COALESCE(td.typtype, tb.typtype, t.typtype) = 'e'::char
        THEN array_to_string((SELECT array_agg(enumlabel) FROM pg_enum WHERE enumtypid = COALESCE(td.oid, tb.oid, a.atttypid))::varchar[], ',')
        ELSE NULL
    END AS enum_values,
    CASE atttypid
         WHEN 21 /*int2*/ THEN 16
         WHEN 23 /*int4*/ THEN 32
         WHEN 20 /*int8*/ THEN 64
         WHEN 1700 /*numeric*/ THEN
              CASE WHEN atttypmod = -1
               THEN null
               ELSE ((atttypmod - 4) >> 16) & 65535
               END
         WHEN 700 /*float4*/ THEN 24 /*FLT_MANT_DIG*/
         WHEN 701 /*float8*/ THEN 53 /*DBL_MANT_DIG*/
         ELSE null
      END   AS numeric_precision,
      CASE
        WHEN atttypid IN (21, 23, 20) THEN 0
        WHEN atttypid IN (1700) THEN
        CASE
            WHEN atttypmod = -1 THEN null
            ELSE (atttypmod - 4) & 65535
        END
           ELSE null
      END AS numeric_scale,
    CAST(
             information_schema._pg_char_max_length(information_schema._pg_truetypid(a, t), information_schema._pg_truetypmod(a, t))
             AS numeric
    ) AS size,
    a.attnum = any (ct.conkey) as is_pkey,
    COALESCE(NULLIF(a.attndims, 0), NULLIF(t.typndims, 0), (t.typcategory='A')::int) AS dimension
FROM
    pg_class c
    LEFT JOIN pg_attribute a ON a.attrelid = c.oid
    LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
    LEFT JOIN pg_type t ON a.atttypid = t.oid
    LEFT JOIN pg_type tb ON (a.attndims > 0 OR t.typcategory='A') AND t.typelem > 0 AND t.typelem = tb.oid OR t.typbasetype > 0 AND t.typbasetype = tb.oid
    LEFT JOIN pg_type td ON t.typndims > 0 AND t.typbasetype > 0 AND tb.typelem = td.oid
    LEFT JOIN pg_namespace d ON d.oid = c.relnamespace
    LEFT JOIN pg_constraint ct ON ct.conrelid = c.oid AND ct.contype = 'p'
WHERE
    a.attnum > 0 AND t.typname != ''
    AND c.relname = 'info'
    AND d.nspname = 
ORDER BY
    a.attnum;'

in /app/vendor/craftcms/cms/src/db/MigrationManager.php:256

Stack trace:
#0 /app/vendor/craftcms/cms/src/console/controllers/InstallController.php(161): craft\db\MigrationManager->migrateUp(Object(craft\migrations\Install))
#1 [internal function]: craft\console\controllers\InstallController->actionCraft()
#2 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /app/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#4 /app/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('', Array)
#5 /app/vendor/craftcms/cms/src/console/Controller.php(199): yii\console\Controller->runAction('', Array)
#6 /app/vendor/yiisoft/yii2/base/Module.php(528): craft\console\Controller->runAction('', Array)
#7 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('install', Array)
#8 /app/vendor/craftcms/cms/src/console/Application.php(93): yii\console\Application->runAction('install', Array)
#9 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('install', Array)
#10 /app/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#11 /app/craft(22): yii\base\Application->run()
#12 {main}

Steps to reproduce

  1. Create project with Composer
  2. Set config vars for ENVIRONMENT to "dev" and SECURITY_KEY to random string
  3. Provision empty Postgres database add-on on Heroku

Additional info

  • Craft version: 3.3.4.1
  • PHP version: 7.3.7
  • Database driver & version: pgsql 11.5
  • Plugins & versions: Embedded Assets, Redactor

Most helpful comment

Wrote a tutorial on getting Craft deployed on Heroku in case anyone else has issues.

All 5 comments

After that stack trace, were there any additional error details or additional stack trace(s)?

Nope that is the entire stack trace. Will try and repro again later.

Figured out the answer, was somewhat unrelated getting the admin installer to run. In Heroku's settings under Config vars, there are a series of environment variables you need to add that match your local .env file: ENVIRONMENT, SECURITY_KEY, and DB_SCHEMA.

Glad you got it sorted!

Wrote a tutorial on getting Craft deployed on Heroku in case anyone else has issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timkelty picture timkelty  路  3Comments

michaelhue picture michaelhue  路  3Comments

leigeber picture leigeber  路  3Comments

mccombs picture mccombs  路  3Comments

davist11 picture davist11  路  3Comments