Deleting a category
I'm trying to delete a category via ZED - category - delete
But then I get this message: Unable to execute statement [DELETE FROM spy_category WHERE spy_category.id_category=:p1]
There is no futher information about the why. Would think there is still some reference to that specific category. But on what places should I think of? Usage in navigation / CMS pages / Product linking?
Would be nice to have just some more specific information.
Best Answers
-
What I do in such cases is to copy-paste the query and run it manually in my database tool. This will give me a better error message.
You may also have a look into \Propel\Runtime\ActiveQuery\QueryExecutor\AbstractQueryExecutor::handleStatementExceptionIf the debug mode is not enabled, Propel will not add the actual database error to the logged message. Afair debug mode is never enabled in Spryker by default, even not in local environment.
If I'm allowed to take a wild guess, your problem is most likely foreign key relations. There are entities in other tables that relate to the category entities. You are not allowed to delete categories until all the relations were deleted before.
Most database systems including MySQL, and Propel, supports cascading. So in theory you could define your related entities to be automatically deleted if the parent entity is deleted:
But usually Spryker does not make use of this and you have to delete the entities via PHP first.
0 -
Found it via debugging. Apparently I have some category filters active. The internal error message was about the constraint with the product category filter table.
Removing those filters (back to default in zed) was the key
1
Answers
-
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,056 ⚖️ - Guardians (admin)
Heyhey,
I took a look at my local environment with the ootb b2b-demo-shop 202307.0 installed.I can not reproduce this. I think you do not get more information because it is a fatal error which should not happen.
If I look through the code it seems that error you are describing is happening when the specified category should be deleted in the database. So I assume at that point it is already deleted (and because of exception rolled-back) or some read/write problem.
Have a look at
vendor/spryker/category/src/Spryker/Zed/Category/Business/Deleter/CategoryDeleter.php
- all of the logic is executed transactional. so maybe some plugin is deleting that category already and once$this->categoryEntityManager->deleteCategory($idCategory);
is called you get the exception.Hope this helps you to debug further. Let me know once you found the problem :)
All the best,
Florian
0 -
What I do in such cases is to copy-paste the query and run it manually in my database tool. This will give me a better error message.
You may also have a look into \Propel\Runtime\ActiveQuery\QueryExecutor\AbstractQueryExecutor::handleStatementExceptionIf the debug mode is not enabled, Propel will not add the actual database error to the logged message. Afair debug mode is never enabled in Spryker by default, even not in local environment.
If I'm allowed to take a wild guess, your problem is most likely foreign key relations. There are entities in other tables that relate to the category entities. You are not allowed to delete categories until all the relations were deleted before.
Most database systems including MySQL, and Propel, supports cascading. So in theory you could define your related entities to be automatically deleted if the parent entity is deleted:
But usually Spryker does not make use of this and you have to delete the entities via PHP first.
0 -
It is indeed a constraint with spy_category_attribute.
But that table will always be filled. Wouldn't think all the data should first be deleted manually before removing the category?
0 -
Found it via debugging. Apparently I have some category filters active. The internal error message was about the constraint with the product category filter table.
Removing those filters (back to default in zed) was the key
1
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 69 Spryker News
- 896 Developer Corner
- 758 Spryker Development
- 83 Spryker Dev Environment
- 361 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 23 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 68 Spryker Safari Questions
- 50 Random