magento2: Notice: Undefined index: {{table_name}} in /var/www/html/vendor/magento/framework/Setup/Declaration/Schema/Declaration/SchemaBuilder.php on line 354
Preconditions (*)
When one module with db_schema
has a constraint on another module where the table is created via Install/Upgrade Schema
it leads to the error mentioned in the title.
This happens on Magento version 2.4.3-p2, 2.4.4
Steps to reproduce (*)
- Require https://github.com/mageplaza/magento-2-blog
- Run
bin/magento setup:upgrade
. - Create a module with this
db_schema.xml
file:
<?xml version="1.0" ?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="test_mageplaza" comment="Test Mageplaza Blog Posts">
<column name="project_id" xsi:type="int" nullable="false" identity="false" unsigned="true" comment="Project ID"/>
<column name="post_id" xsi:type="int" padding="10" unsigned="true" nullable="false" comment="Post ID"/>
<index referenceId="TEST_MAGEPLAZA_BLOG_POSTS_POST_ID" indexType="btree">
<column name="post_id"/>
</index>
<constraint xsi:type="foreign" referenceId="FK_4D4A10A4534D098BDCCE6BC9C2CABAD7" table="test_mageplaza" column="project_id" referenceTable="test_project" referenceColumn="project_id" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="FK_FAF4B768352B9AD4307CC7AFD4E2932A" table="test_mageplaza" column="post_id" referenceTable="mageplaza_blog_post" referenceColumn="post_id" onDelete="CASCADE"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="project_id"/>
<column name="post_id"/>
</constraint>
</table>
</schema>
- Run
bin/magento setup:upgrade
.
Expected result (*)
1.Setup upgrade runs without issues
Actual result (*)
Notice: Undefined index: mageplaza_blog_post in /var/www/html/vendor/magento/framework/Setup/Declaration/Schema/Declaration/SchemaBuilder.php on line 354
Somehow Magento tries to apply the same foreign key if one module uses Install/Upgrade Schema and the other uses db_schema.xml
Additional information to reproduce the issue
- Create a directory under
app/code
calledTest/Module
. - Copy the contents from https://github.com/BorisovskiP/test-module to that directory.
- Run
bin/magento setup:upgrade
Expected result:
Both tables should be created
Actual result:
Warning: Undefined array key "test_table" in /var/www/html/vendor/magento/framework/Setup/Declaration/Schema/Declaration/SchemaBuilder.php on line 354
Tested on Magento 2.4.4, PHP 8.1.4
For PHP 7.4 the message is the one from the title of this issue.
You can also test that if you comment out the contents of db_schema.xml
and run setup:upgrade
the test_table
(defined in \Test\Module\Setup\InstallSchema
) will be created, and once you revert the commented section and again run setup:upgrade
the same error message will be thrown.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 15 (9 by maintainers)
We ran into the same issue this morning on a local environment, but for table
wishlist
. Here is how it has been unlocked:vendor/magento/framework/Setup/Declaration/Schema/Declaration/SchemaBuilder.php
$referenceData['referenceTable'] = $this->tables[$referenceTableName];
php bin/magento setup:upgrade
( Should run through with no errors )vendor/magento/framework/Setup/Declaration/Schema/Declaration/SchemaBuilder.php
again and remove the modification.php bin/magento setup:upgrade
again ( Should run through with no errors )After this we stopped investigating it further.