- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to update a category and got an error.
I did these steps:
- I removed all my categories with below query
SET FOREIGN_KEY_CHECKS = 0;
DELETE FROM catalog_category_entity WHERE entity_id > 2;
DELETE FROM url_rewrite WHERE entity_type = 'category';
SET FOREIGN_KEY_CHECKS = 1; - I added some category by code. It is showing fine in the backend and frontend. I have no issue with this.
- After that I added some product and assign a category in csv but category is not showing in the added products and when I try to update this with assign category
it is showing me an error "No such entity with id = 3" - Also when I try to update any category it is showing same error "No such entity with id = 3"
Please resolve, If you know anything about this.
I run the reindex command and cache flush command but it's not working.
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I commented a code in vendor\magento\module-catalog\Model\CategoryRepository.php file line no. 141
if (!$category->getId()) { throw NoSuchEntityException::singleField('id', $categoryId); }
Now it is working fine.
Please let me know it is the correct way or not or I need to do something else.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
Hi @Neeraj02381
Looks like you have some issue related to store
Run below script and then check
SET FOREIGN_KEY_CHECKS=0; UPDATE `store` SET store_id = 0 WHERE code='admin'; UPDATE `store_group` SET group_id = 0 WHERE name='Default'; UPDATE `store_website` SET website_id = 0 WHERE code='admin'; UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN'; SET FOREIGN_KEY_CHECKS=1;
After running this - run indexing command again like - php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush
Then check it might works for you !
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
I already try this but didn't get any luck
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
Hi @Neeraj02381
ok i understand ! can you please check error log in var/log directory and post over here ? so its help us to troubleshoot the issue
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
Here is my exception.log
[2018-06-19 11:08:52] main.CRITICAL: No such entity with id = 3 {"exception":"[object] (Magento\\Framework\\Exception\\NoSuchEntityException(code: 0): No such entity with id = 3 at D:\\xampp\\htdocs\\meg\\vendor\\magento\\framework\\Exception\\NoSuchEntityException.php:49)"} []
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I commented a code in vendor\magento\module-catalog\Model\CategoryRepository.php file line no. 141
if (!$category->getId()) { throw NoSuchEntityException::singleField('id', $categoryId); }
Now it is working fine.
Please let me know it is the correct way or not or I need to do something else.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
Root cause of this issue is data in url_rewrite table related to removed category id 3.
select * from url_rewrite where target_path like '%/category/3%'
delete from url_rewrite where target_path like '%/category/3%';
select * from url_rewrite where entity_type='category' and entity_id=3;
delete from url_rewrite where entity_type='category' and entity_id=3;
I fixed similar issue by above workaround.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
Oops!
select * from url_rewrite where target_path like '%/category/3';
delete from url_rewrite where target_path like '%/category/3';
Delete only rows with target path end with /category/3.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
This is not the right way. We cannot edit the core file to hide issues.
Assuming your site is in `Developer Mode`, you can change it to `Production Mode` and clear/flush cache and then switch back to `Developer Mode`.
I had this issue in the front end, as i recently moved the database from one server to another. I have managed to solve by this way.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: No such entity with id = 3
Tried your solution and received:
MySQL returned an empty result set (i.e. zero rows)
and
0 rows affected.
What else can it be?