Skip to content

Can't create foreignKey with Declarative Schema on table not created through DS #21770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
peterjaap opened this issue Mar 15, 2019 · 20 comments
Closed
Labels
bug report Component: Framework/Setup USE ONLY for FRAMEWORK RELATED BUG! E.g If bug occurs during Catalog Setup use just Catalog feature request Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Progress: done Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@peterjaap
Copy link
Contributor

peterjaap commented Mar 15, 2019

Preconditions (*)

  1. Magento 2.3.0

Steps to reproduce (*)

  1. Create a module that uses Declarative Schema by creating a db_schema.xml
  2. Try to create a foreignKey with as referenceTable a table that isn't created/controlled through Declarative Schema (in my case a 3rd party extension's table)
  3. Run php bin/magento setup:upgrade

Expected result (*)

  1. Table is created with a foreign key to referenced table

Actual result (*)

  1. Error Notice: Undefined index: referenced_table_name_here in vendor/magento/framework/Setup/Declaration/Schema/Declaration/SchemaBuilder.php on line 352

When I edit vendor/magento/framework/Setup/Declaration/Schema/SchemaConfig.php:77 and add print_r(array_keys($data['table']));exit; there, I get a list of all tables created by extensions that use Declarative Schema. The referenced table isn't one of them and thus setup:upgrade throws an error.

@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Mar 15, 2019

Hi @peterjaap. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@peterjaap do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Mar 15, 2019
@ghost ghost self-assigned this Mar 18, 2019
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Mar 18, 2019

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • Next steps are available in case you are a member of Community Maintainers.

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@ghost ghost added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Component: Setup feature request labels Mar 18, 2019
@ghost
Copy link

ghost commented Mar 18, 2019

Hi @peterjaap thank you for you report, It will be processed faster if you move this to https://github.com/magento/community-features

@ghost ghost closed this as completed Mar 18, 2019
@peterjaap
Copy link
Contributor Author

@engcom-backlog-nazar but it's not a feature? It's a bug!

@peterjaap peterjaap reopened this Mar 18, 2019
@ghost
Copy link

ghost commented Mar 18, 2019

@peterjaap according to devdocs, seems like no.

@ghost
Copy link

ghost commented Mar 18, 2019

@peterjaap In the following example, the selected constraint node defines the characteristics of the FL_ALLOWED_SEVERITIES foreign key. https://magento-devdocs.github.io/devdocs-for-tests/guides/v2.3/extension-dev-guide/declarative-schema/db-schema.html

@peterjaap
Copy link
Contributor Author

@engcom-backlog-nazar could you elaborate on that?

@ghost
Copy link

ghost commented Mar 18, 2019

@peterjaap this mean that you can create a foreign key only with tables created by declarative schema, because all table data loaded now with checking db_schema.xml

@peterjaap
Copy link
Contributor Author

peterjaap commented Mar 18, 2019

Ok maybe it's an idea to add that in plain English?

And imho this is a serious impediment for the adoption of declarative schema. I've fallen back to writing InstallScripts again....

@ghost
Copy link

ghost commented Mar 18, 2019

@peterjaap seems, like yes, but adding a check data table on install scripts, sounds like feature request. on my opinion

@peterjaap
Copy link
Contributor Author

I meant adding it to the docs instead of that weird sentence about FL_ALLOWED_SEVERITIES.

@ghost
Copy link

ghost commented Mar 18, 2019

@peterjaap devdoc always have not clearly documentation :) but you can create a PR to solve this here -> https://github.com/magento/devdocs

@ghost ghost removed their assignment Mar 19, 2019
@Yonn-Trimoreau
Copy link

@engcom-backlog-nazar The sentence about FL_ALLOWED_SEVERITIES does not mention the fact that you cannot add a foreign key referencing a table not created through db_schema.xml... I read the sentence again and again.. Nope.

Seems like an issue.

Like @peterjaap said, this is a serious impediment for the adoption of declarative schema.

@ghost
Copy link

ghost commented Apr 1, 2019

@Yonn-Trimoreau at this point, yes we must have ability to add foreign key to tables wich not created via db schema.xml but it's more a "feature" to my opinion, because db_schema.xml not cover this case.

@Yonn-Trimoreau
Copy link

@engcom-backlog-nazar If we read the documentation again and take what is explicitly written about this issue:

Declarative setup is based on database structure declarations, and is used in projects such as Doctrine. Schema files declare what the database structure should be, and Magento determines the differences between the current table structure and what it should be. These differences can be represented with atomic SQL operations.

Two things:

  • Magento determines the differences between the current table structure and what it should be. Sounds cristal clear to me.

  • and is used in projects such as Doctrine: Doctrine does that. It can create foreign keys with external tables not described in any of its description formats. By using the @joincolumn annotation. Because Doctrine applies its migration scripts based on the real database structure. Not on its own representation of the database structure.

@AnshuMishra17
Copy link
Contributor

AnshuMishra17 commented Apr 26, 2019

What is the status on this issue?
I am facing this issue on 2.3.1

@joshuaadickerson
Copy link

This is not a feature request. This is implementing the backwards compatibility that was promised.

@sdzhepa sdzhepa added Component: DB Component: Framework/DB USE ONLY for FRAMEWORK RELATED BUG! Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release and removed Component: DB Component: Framework/DB USE ONLY for FRAMEWORK RELATED BUG! labels Jul 12, 2019
@sdzhepa sdzhepa added Component: Framework/Setup USE ONLY for FRAMEWORK RELATED BUG! E.g If bug occurs during Catalog Setup use just Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Component: Setup labels Jul 12, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @sdzhepa
Thank you for verifying the issue. Based on the provided information internal tickets MC-18156 were created

Issue Available: @sdzhepa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@khnaim
Copy link

khnaim commented Oct 15, 2020

What is the status on this issue?
I am facing this issue on Magento CLI 2.4.1

@ghost ghost removed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Oct 20, 2020
@sdzhepa sdzhepa added Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it and removed Progress: ready for dev labels Oct 29, 2020
@sivaschenko
Copy link
Member

Closing this issue as there is no plans to implement external references for the db schema. The reference to the table added in a custom way should be added in a custom way as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Framework/Setup USE ONLY for FRAMEWORK RELATED BUG! E.g If bug occurs during Catalog Setup use just Catalog feature request Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Progress: done Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

No branches or pull requests

9 participants