moacode / craft-fab-permissions

Restrict access to fields and tabs for particular user groups across your Craft elements.
Other
16 stars 9 forks source link

Plugin installation failed for Craft 3.7.13 and PostgreSQL #28

Open ivanBereznev opened 3 years ago

ivanBereznev commented 3 years ago

Hello,

first of all, I am not sure if this plugin is supposed to work with Craft 3.7 at all, since README says about 3.5. But I've seen something about compatibility with 3.7 in git history, so decided to post the issue.

I've tried to install plugin and got the following error:

2021-09-24 12:32:30 [-][3][-][error][craft\db\MigrationManager::migrateUp] Failed to apply Install (time: 0.127s). Output:
    > create table {{%fabpermissions_fieldlayoutpermissions}} ... done (time: 0.089s)
    > add foreign key fk_cgjscdcamvbkgwrgotgvbxsuisfyititfzyt: {{%fabpermissions_fieldlayoutpermissions}} (siteId) references {{%sites}} (id) ... done (time: 0.002s)
    > add foreign key fk_qbcsiwloqootfbkzzljxzmhjcwhazowevjni: {{%fabpermissions_fieldlayoutpermissions}} (tabId) references {{%fieldlayouttabs}} (id) ... done (time: 0.017s)
    > add foreign key fk_gyktbsoskhfdxzmbntibrzhsckbbmpuhzxjk: {{%fabpermissions_fieldlayoutpermissions}} (fieldId) references {{%fieldlayoutfields}} (fieldId) ...Exception: SQLSTATE[42830]: Invalid foreign key: 7 ERROR:  there is no unique constraint matching given keys for referenced table "fieldlayoutfields"
The SQL being executed was: ALTER TABLE "fabpermissions_fieldlayoutpermissions" ADD CONSTRAINT "fk_gyktbsoskhfdxzmbntibrzhsckbbmpuhzxjk" FOREIGN KEY ("fieldId") REFERENCES "fieldlayoutfields" ("fieldId") ON DELETE CASCADE ON UPDATE CASCADE (/app/vendor/yiisoft/yii2/db/Schema.php:678)
#0 /app/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE "fa...')
#1 /app/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('ALTER TABLE "fa...')
#2 /app/vendor/yiisoft/yii2/db/Migration.php(467): yii\db\Command->execute()
#3 /app/vendor/craftcms/cms/src/db/Migration.php(382): yii\db\Migration->addForeignKey('fk_gyktbsoskhfd...', '{{%fabpermissio...', 'fieldId', '{{%fieldlayoutf...', 'fieldId', 'CASCADE', 'CASCADE')
#4 /app/vendor/thejoshsmith/craft-fab-permissions/src/migrations/Install.php(167): craft\db\Migration->addForeignKey('fk_gyktbsoskhfd...', '{{%fabpermissio...', 'fieldId', '{{%fieldlayoutf...', 'fieldId', 'CASCADE', 'CASCADE')
#5 /app/vendor/thejoshsmith/craft-fab-permissions/src/migrations/Install.php(54): thejoshsmith\fabpermissions\migrations\Install->addForeignKeys()
#6 /app/vendor/craftcms/cms/src/db/Migration.php(52): thejoshsmith\fabpermissions\migrations\Install->safeUp()
#7 /app/vendor/craftcms/cms/src/db/MigrationManager.php(232): craft\db\Migration->up(true)
#8 /app/vendor/craftcms/cms/src/base/Plugin.php(140): craft\db\MigrationManager->migrateUp(Object(thejoshsmith\fabpermissions\migrations\Install))
#9 /app/vendor/craftcms/cms/src/services/Plugins.php(536): craft\base\Plugin->install()
#10 /app/vendor/craftcms/cms/src/controllers/PluginsController.php(49): craft\services\Plugins->installPlugin('craft-fab-permi...', 'standard')
#11 [internal function]: craft\controllers\PluginsController->actionInstallPlugin()
#12 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#13 /app/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#14 /app/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('install-plugin', Array)
#15 /app/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('install-plugin', Array)
#16 /app/vendor/craftcms/cms/src/web/Application.php(277): yii\base\Module->runAction('plugins/install...', Array)
#17 /app/vendor/craftcms/cms/src/web/Application.php(586): craft\web\Application->runAction('plugins/install...', Array)
#18 /app/vendor/craftcms/cms/src/web/Application.php(256): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#19 /app/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#20 /app/web/index.php(21): yii\base\Application->run()
#21 {main}

Craft CMS version: 3.7.13 PostgreSQL version: 13.4

ivanBereznev commented 3 years ago

Looks like the reason is that fieldlayoutfields.fieldId is not a primary key and so is not unique, and foreign key is expected to reference a single row. So probably this is not related to specific Craft version.

mccombs commented 2 years ago

Ran into the exact same issue.