cancel
Showing results for 
Search instead for 
Did you mean: 

No such entity with id = 3

SOLVED
Highlighted

No such entity with id = 3

I am trying to update a category and got an error.


I did these steps:

  1.  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;

  2. I added some category by code. It is showing fine in the backend and frontend. I have no issue with this.
  3. 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"
  4. 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.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: No such entity with id = 3

@Manthan Dave

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.

View solution in original post

13 REPLIES 13
Highlighted

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 !

if issue solved,Click Kudos & Accept as Solution
Highlighted

Re: No such entity with id = 3

I already try this but didn't get any luck

Highlighted

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

if issue solved,Click Kudos & Accept as Solution
Highlighted

Re: No such entity with id = 3

@Manthan Dave:

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)"} []

 

 

 

Highlighted

Re: No such entity with id = 3

@Manthan Dave

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.

View solution in original post

Highlighted

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.

 

Highlighted

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.

 

Highlighted

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.

Highlighted

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?