alankent / magento2devbox-skeleton

Skeleton files for a new DevBox related project.
22 stars 10 forks source link

magento setup command is throwing magento.flag does't exist. #4

Open spraj-zz opened 6 years ago

spraj-zz commented 6 years ago

While hitting the command: magento setup:install --db-host=db --db-name=magento2 --db-user=root --db-password=root --admin-firstname=Magento --admin-lastname=Administrator --admin-email=user@example.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --backend-frontname=admin

An error is thrown as: [Zend_Db_Statement_Exception]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento2.flag' doesn't exist, query wa
s: SELECT flag.* FROM flag WHERE (flag.flag_code='staging')

[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento2.flag' doesn't exist

Please help!

SebastienTolron commented 6 years ago

Same here !

Starting Magento installation: File permissions check... [Progress: 1 / 933] Required extensions check... [Progress: 2 / 933] Enabling Maintenance Mode... [Progress: 3 / 933] Installing deployment configuration... [Progress: 4 / 933] Installing database schema:

[Zend_Db_Statement_Exception]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.flag' doesn't exist, query was: SELECT flag.* FROM flag WHERE (flag.flag_code='staging')

gigadesign1 commented 5 years ago

Try to delete your env.php file in app/etc/env.php

That fixed it for me.

vbuck commented 5 years ago

While @gigadesign1 provides a viable solution, I think it's important to continue to understand the why. I haven't been able to yet isolate which module (presumably a core module) creates the condition, but I found a related issue here which speaks to how dependency injection can initialize things unexpectedly:

SebastienTolron commented 5 years ago

Ok, so , @vbuck is right. This is not not an issue with the cache , or env.php or anything.

This is an issue with custom commands cli.

Indeed , for example , if you are adding Dependency injection in your custom command cli for storeManager for example this won't work.

Just comment out every custom command for installation and it will work.

On my side what I did , is changing the the dependency injection , and using object Manager instead.

This is a bad practice . but I think for command cli , this is the best thing to do. This is clearly an issue of the conception in Magento core.

Good luck guys

oliverde8 commented 5 years ago

To continue on this subject. This issue can indeed come from custom commands cli, but there is a second possibility.

If you (or any modules you install) override a class that is used by the magento setup, and modifies the dependencies and adds for example a dependency to storeManager you will get the same error.

For example if you override \Magento\Catalog\Helper\Product and inject Magento\Customer\Model\ResourceModel\CustomerRepository you will create a dependency to Magento\Framework\Locale\Resolver which calls to the database in the constructor.

I would say the way to debug this is to :

Modify vendor/magento/framework/ObjectManager/ObjectManager.php at the function public function get($type) and put the fallowing content for the if.

if (!isset($this->_sharedInstances[$type])) {
            try {
                $this->_sharedInstances[$type] = $this->_factory->create($type);
            } catch (\Exception $exception) {
                echo "At fault : $type\n";
                throw $exception;
            }
        }

This will print before the exception something like

At fault : Magento\Customer\Model\ResourceModel\Address
At fault : Magento\Customer\Model\ResourceModel\AddressRepository
At fault : MyProject\Catalog\Helper\Product
At fault : Magento\Catalog\Model\Product\Attribute\Repository
At fault : Magento\Catalog\Console\Command\ProductAttributesCleanUp

Which allows me to see that the issue is with MyProject\Catalog\Helper\Product

Good luck finding your issues.

riconeitzel commented 3 years ago

Instead of using the ObjectManager you could inject a proxy class instead! https://devdocs.magento.com/guides/v2.4/extension-dev-guide/proxies.html

pmsteil commented 2 years ago

The solution by @oliverde8 helped me also... by injecting that code into the ObjectManager.php

This should be a standard in Magento code to help debug such problems...

ashvinimarwal commented 2 years ago

This worked for me on Adobe commerce 2.3 php bin/magento setup:uninstall rm -rf var/cache/ var/di/ var/page_cache/ generated/ pub/static/ php bin/magento setup:install --cleanup-database ...other options...

vpodorozh commented 11 months ago

Here is a working solution to prevent issues with custom CLI commands using the connection to DB in constructors:

https://github.com/run-as-root/magento-cli-auto-proxy

composer req run_as_root/magento-cli-auto-proxy:^1

It automatically makes proxies for all CLI command arguments.

P.S.: for sure, it is better to fix your code by using proxies, for example, but if you have no control over an extension with this problem - current solution will help you out.