Magento 2 - SQLSTATE[42S02]: Base table or view not found when running a reindex - magento2

I am getting the following error on terminal when running bin/magento indexer:reindex:
***SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catalog_product_index_price_cfg_opt_temp' doesn't exist, query was: DESCRIBE `catalog_product_index_price_cfg_opt_temp.
I have checked the website database and can confirm the table does exist but with no data.
catalog_product_index_price_cfg_opt_tmp table
When I manually run the SQL query (DESCRIBE `catalog_product_index_price_cfg_opt_temp) it created data.
However, when I try re-running the bin/magento indexer:reindex command following this, it removed the data created when running the above SQL command and i still get the same below error on terminal
***SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catalog_product_index_price_cfg_opt_temp' doesn't exist, query was: DESCRIBE `catalog_product_index_price_cfg_opt_temp.
Hopefully you can help me to resolve this. Thank you!

Check if you are setting the table prefix correct in app/etc/env.php
...
'db' => [
'table_prefix' => 'pref_',
'connection' => [
'default' => [
'host' => 'localhost',
'dbname' => 'magentodb',
'username' => 'user',
'password' => 'pass',
'model' => 'mysql5',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
]
]
],
...
And do bin/magento indexer:reset

Related

Shopware 6 - Create product programmatically

I have a command script to import products from csv file.
The code i use to create the product is:
$this->productRepository->create([[
'id' => Uuid::randomHex(),
'name' => 'exampls',
'taxId' => 'b6e10c80b24946a48bb74e742d280c75',
'stock' => 999,
'createdAt' => '2022-01-01T10:17:05+02:00',
'price' => [
[
'currencyId' => 'b7d2554b0ce847cd82f3ac9bd1c0dfca',
'gross' => 99,
'net' => 99,
'linked' => true,
]
],
'productNumber' => $suffix,
'visibilities' => [
[
'salesChannelId' => '5ce47a708e484e4d8c20221f8cdfa08f',
'visibility' => ProductVisibilityDefinition::VISIBILITY_ALL,
],
],
]], Context::createDefaultContext());
I get the following error:
An exception occurred while executing 'INSERT INTO `product` (`id`, `version_id`, `parent_version_id`, `product_manufacturer_versio
n_id`, `tax_id`, `product_media_version_id`, `cms_page_version_id`, `price`, `product_number`, `stock`, `restock_time`, `active`, `
is_closeout`, `purchase_steps`, `min_purchase`, `shipping_free`, `created_at`) VALUES ('���zgL��vc�.�p','���jK¾K��u,4%','���
jK¾K��u,4%','���jK¾K��u,4%','��
��IF���Nt-(
u','���jK¾K��u,4%','���jK¾K��u,4%','{\"cb7d2554b0ce847cd82f3ac9bd1c0dfca\":{\
"currencyId\":\"b7d2554b0ce847cd82f3ac9bd1c0dfca\",\"gross\":99.0,\"net\":99.0,\"linked\":true}}','62e2977934944','999',NULL,'1','0
','1','1','0','2022-01-01 08:17:05.000');':
What could i do to get it working? And if there is another way to approach this, i'm open for suggestions. Just started learning Shopware :)
At first glance this looks to be correct. The error message seems to be incomplete. It should say after the query why it failed, be it a syntax error or a wrong foreign key. The latter would be my best guess at what could fail the moment, have you checked all the uuids to exist in their corresponding tables like tax, currency and sales_channel?

PHP Warning in Typo3DatabaseBackend line 158 after updating DDEV to 1.19

After updating DDEV to 1.19 I get following error after backend login in TYPO3 11.5.8:
PHP Warning: gzuncompress(): need dictionary in
/var/www/html/public/typo3/sysext/core/Classes/Cache/Backend/Typo3DatabaseBackend.php
line 158
I already tried a lot of things:
I have tried all officially PHP versions which are possible with DDEV.
I have downgraded doctrine/dbal 2.13.8, 2.13.7, 2.13.6, ...
I have downgraded MariaDB 10.3 to 10.2
Nothing works. So it needs a deeper view of the problem:
In Typo3DatabaseBackend.php at line 158 I have added
$tmp = gzuncompress($data);
With help of xdebug I can see that uncompress works without any problems. So, IMO it can't be a zlib problem.
As next step I have converted the compressed $data with bin2hex($data) into $tmp and in my database I have tried to HEX the value, too:
SELECT uid, CONVERT(content USING utf8) FROM cache_rootline WHERE uid = 1;
Interesting point:
Before: 789c4d904172c3200
In DB: 0x783f4d3f41723f200
Select: 783f4d3f41723f200
Nearly each 2nd byte is correct, but the other bytes are totally wrong.
I have exported my MariaDB data and switched to MySQL 8.0 and imported the data again. Because of some utf8mb4_unicode_ci incompatibilities I have recreated all cache tables with help of Installtool of TYPO3.
After login to TYPO3 backend I got following error:
General error: 3988 Conversion from collation utf8_general_ci into utf8mb4_unicode_ci impossible
I have searched full TYPO3 project, but I can't find utf8_general_ci anywhere.
Do you have any idea, what could be wrong?
Thank you for your help.
Stefan
On new DDEV project four LocalConfiguration looks something like that:
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf8',
'driver' => 'mysqli',
],
],
],
and DDEV creates following to your AdditionalConfiguration.php
'DB' => [
'Connections' => [
'Default' => [
'dbname' => 'db',
'driver' => 'pdo_mysql',
'host' => 'db',
'password' => 'db',
'port' => '3306',
'user' => 'db',
],
],
],
Maybe you have added following to your configuration to create new tables with a specific collation:
'DB' => [
'Connections' => [
'Default' => [
...
'tableoptions' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_general_ci',
],
],
],
],
Do you see the problem? The charset option of LocalConfiguration.php was NOT overwritten in your AdditionalConfiguration. So, you have a charset miss-match in your configuration. Please keep them in sync.
Either set collation back to utf8_unicode_ci or add:
'charset' => 'utf8mb4',
in AdditionalConfiguration.php
Have fun with TYPO3
Stefan
For me the easiest way was to replace the pdo_mysql driver with mysqli.
Because I'm only using MariaDB and my database was utf8_general_ci encoded, this was the easiest fix/help.

MongoDB with Laravel 8 Authentication Failed upon php artisan migrate

I Installed mongoDB in my laravel 8 project for first time, to explore mongoDB functionalities
When I run php artisan migrate I got:
MongoDB\Driver\Exception\AuthenticationException
Authentication failed.
at D:\xampp\htdocs\Mongo\mongonews\vendor\mongodb\mongodb\src\Command\ListCollections.php:115
my : D:\xampp\htdocs\Mongo\mongonews\config\database.php I set the following:
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
// here you can pass more settings to the Mongo Driver Manager
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'), // required with Mongo 3+
],
],
And this is my .env:
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=mongonews
DB_USERNAME=root
DB_PASSWORD=
Thanks Geaks, appreciate your help to start my first time mongo db based laravel app
All the best.
It was solved by removing username from DB_USERNAME
although It is supposed to be "root" in my case!!!!
DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=news
DB_USERNAME=
DB_PASSWORD=
Hope this helps who ever faced this problem.

How to define a user with SELECT privileges with puppet?

I want to create a user in postgres who can only made SELECT in all the tables of the current database.
How can specify ALL tables in puppet?
Here an extract of my puppet file:
...
postgresql::server::database_grant { 'PnBP':
privilege => 'CREATE',
db => 'db',
role => 'role',
}
postgresql::server::table_grant { 'SELECT':
privilege => 'SELECT',
table => 'ALL',
db => 'db',
role => 'role',
}
...
But when I specify the word ALL it doesn't work.
Here the error:
Error: /Stage[main]/Main/Node[default]/Postgresql::Server::Table_grant[PnBP]/Postgresql::Server::Grant[table:PnBP]/Postgresql_psql[grant:table:PnBP]: Could not evaluate: Error evaluating 'unless' clause, returned pid 30443 exit 1: 'ERROR: relation "all" does not exist
'
I check the doc, but it doesn't specify how to apply the privileges for all the tables.
table : Specifies the table to which you are granting access.
postgresql::server::table_grant
The Puppet documentation for Postgresql describes a postgresql::server::grant option that looks more flexible than the table_grant which assumes a single table.
Looks to be something like:
postgresql::server::grant{ 'SELECT':
object_type => 'ALL TABLES IN SCHEMA',
object_name => 'public',
privilege => 'SELECT',
db => 'db',
role => 'role',
}
https://github.com/puppetlabs/puppetlabs-postgresql#postgresqlservergrant

can't make code generator with PostgreSQL

i have a problem in using code generator with PostgreSQL database, i've make configuration in main.php..
...
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123wasis85',
'ipFilters'=>array('127.0.0.1','::1'),
),
),
...
'db'=>array(
'connectionString' => 'pgsql:host=127.0.0.1;port=5432;dbname=yii_first',
'emulatePrepare' => true,
'username' => 'postgres',
'password' => 'anghauz',
'charset' => 'utf8',
),
...
but it still making error result when i used crud generation, this is the error..:
...
CDbConnection failed to open the DB connection: could not find driver
C:\BitNami\apache2\htdocs\yii\framework\gii\generators\crud\CrudCode.php(44)
...
i make it in localhost n using bitnami..
please help me guys for the solutions..
Please go to php.ini file in the installed php folder. Uncomment the below lines.
extension=php_pdo_pgsql.dll
extension=php_pgsql.dll
It worked for me.