Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spraj-zz opened this issue Mar 12, 2018 · 9 comments
Open

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

spraj-zz opened this issue Mar 12, 2018 · 9 comments

Comments

@spraj-zz
Copy link

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!

@Stolr
Copy link

Stolr commented Jun 29, 2018

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
Copy link

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

That fixed it for me.

@vbuck
Copy link

vbuck commented Nov 8, 2018

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:

@Stolr
Copy link

Stolr commented Nov 16, 2018

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
Copy link

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 :

  • disable all modules and enable them one by one till you get the error during install
  • once you identified the module, remove commands lines
    • If the issue is with command lines, fix it by using the ObjectManager during execution 😢
    • If the issue is not with command lines, you will need to modify the core to find the cause of the error

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
Copy link

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
Copy link

pmsteil commented Jul 28, 2021

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
Copy link

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
Copy link

vpodorozh commented Jul 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants