Magento 2 – Error When Running bin/magento setup:upgrade After Creating Module

bin-magentomagento2setup-upgrade

I'm trying to create a module on a local installation of Magento 2.1.4.

i'm getting this error when running bin/magento setup:upgrade:

[Zend_Db_Adapter_Exception]                       
SQLSTATE[HY000] [2002] No such file or directory  

[PDOException]                                    
SQLSTATE[HY000] [2002] No such file or directory  

setup:upgrade [--keep-generated] [--magento-init-params="..."]

After this i tried this solution: Cannot create new module in magento2 – php bin/magento setup:upgrade

The outcome was the same and there is not much explanation on what this did to solve the problem.

I also read solutions from almost a year ago when apparently this was a common issue deleting var/cache, var/generation and var/di but that didn't worked either.

Best Answer

Simple, try the following commands. I have encountered this error, and I have overcome.

rm -rf var/di/* 
rm -rf pub/static/_cache/* 
rm -rf pub/static/frontend/*
rm -rf var/generation/* 
rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf var/view_preprocessed/*

In magento 2

var/di has been replaced by generated/metadata

var/generation has been replaced by generated/code

I switched to Developer Mode, and deleted the below files.

rm -rf generated/metadata/* 
rm -rf pub/static/_cache/* 
rm -rf pub/static/frontend/*
rm -rf generated/code/* 
rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf var/view_preprocessed/*

never delete pub/static/.htaccess. putting star *at the end does not delete .htaccess file in the folder.

you may also need to run setup di compile to optimize and regenerate magento2 file system.

bin/magento setup:di:compile
bin/magento indexer:reindex
Related Topic