magento2开发中常见问题 二

25,Warning: Error while sending QUERY packet.

Warning: Error while sending QUERY packet. PID=2527 in vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php on line 228

这是数据库设置问题。
先找到数据库配置文件

vim /etc/mysql/my.cnf

搜索这2个参数

  • max_allowed_packet
  • wait_timeout

把这2个参数的值改大点,或者直接注释掉,使用默认值。

最后 再重启mysql

systemctl restart mysql

26,product/placeholder/swatch_image.jpg' does not exist.

php bin/magento catalog:image:resize
File 'vendor/magento/module-catalog/view/base/web/images/product/placeholder/swatch_image.jpg' does not exist.

是没有产品图片,服务器里没有找到对应的图片。

需要把catalog_product_entity_media_gallery表里保存的图片链接删掉就行了。或者直接忽略掉这个图片路径。

2.2.x版本的修改方法

至于怎么知道哪个图片有问题,需要调试下代码

vim vendor/magento/module-catalog/Console/Command/ImagesResizeCommand.php

找到

foreach ($productImages as $image) {
                $originalImageName = $image['filepath'];

改成

foreach ($productImages as $image) {
                $originalImageName = $image['filepath'];
                echo $originalImageName;

再执行php bin/magento catalog:image:resize
就会显示图片地址了

iggo@host:/home/www/magento2$ php bin/magento catalog:image:resize
/1/4/1418614449magento-ecommerce-square-logo_2.pngFile '/home/www/magento2/vendor/magento/module-catalog/view/base/web/images/product/placeholder/swatch_image.jpg' does not exist.

2.3.0版本的修改方法

v2.3.0版本代码在 vendor/magento/module-media-storage/Console/Command/ImagesResizeCommand.php
Magento\MediaStorage\Service\ImageResize.php
修改Magento\MediaStorage\Service\ImageResize.php
找到

public function resizeFromThemes(array $themes = null): \Generator
    {

在里面添加如下代码

public function resizeFromThemes(array $themes = null): \Generator
    {
        $count = $this->productImage->getCountAllProductImages();
        if (!$count) {
            throw new NotFoundException(__('Cannot resize images - product images not found'));
        }

        $productImages = $this->productImage->getAllProductImages();
        $viewImages = $this->getViewImages($themes ?? $this->getThemesInUse());

        foreach ($productImages as $image) {
            $originalImageName = $image['filepath'];
            $originalImagePath = $this->mediaDirectory->getAbsolutePath(
                $this->imageConfig->getMediaPath($originalImageName)
            );
//文件不存在就忽略掉
            if(!file_exists($originalImagePath)){
                $count --;
                continue;
            }
            foreach ($viewImages as $viewImage) {
                $this->resize($viewImage, $originalImagePath, $originalImageName);
            }
            yield $originalImageName => $count;
        }

27,MySQL创建触发器的时候报1419错误( 1419 - You do not have the SUPER privilege and binary logging is enabled )

解决方法:
第一步,用root用户登录:mysql -u root -p
第二步,设置参数log_bin_trust_function_creators为1:

set global log_bin_trust_function_creators = 1;

这样有个弊端就是重启服务器后,又还原了,又得重设一遍。
有个一劳永逸的方法就是直接修改my.cnf配置文件,添加

set global log_bin_trust_function_creators = 1;

再重启数据库,就好了

28,Errors during compilation: Magento\Backend\Model\View\Layout\GeneratorPool

Incompatible argument type: Required type: \Magento\Framework\View\Layout\Condition\ConditionFactory. Actual type: \Magento\Framework\App\Config\ScopeConfigInterface; File: /vendor/magento/module-backend/Model/View/Layout/GeneratorPool.php

Total Errors Count: 1

[Magento\Framework\Validator\Exception] Error during compilation

解决方法:
直接删除vendor/magento/module-backend/Model/View/Layout/GeneratorPool.php

rm vendor/magento/module-backend/Model/View/Layout/GeneratorPool.php


https://magento.stackexchange.com/questions/222387/error-during-compilation-after-upgrade-in-magento-2-2-3

29,proc_get_status() has been disabled for security reasons

这是因为安全原因,将proc_get_status函数禁用了,可以通过编辑php的配置文件php.ini,搜索proc_get_status,将他从disable_functions中删除即可。

另外proc_openexec 这几个函数也需要从disable_functions中删除

30, Attribute with ID “Manufacturer” does not exist

从2.2.5升级到2.2.7时,报这个错误。
解决办法:
1,先数据库里搜索有没有这个Manufacturer属性

select attribute_id from eav_attribute where attribute_code = 'manufacturer';

2,如果有这个属性的话,找到这个attribute_id,直接更新catalog_eav_attribute

update catalog_eav_attribute set apply_to = 'simple,virtual,bundle,downloadable,configurable' where attribute_id = 你找到的attribute_id;

3,如果没有这个属性的话,就需要插入到eav_attribute

INSERT INTO `eav_attribute` (`attribute_id`, `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`) VALUES (NULL, '4', 'manufacturer', NULL, NULL, 'varchar', NULL, NULL, 'text', 'Manufacturer', 'validate-length maximum-length-255', NULL, '0', '0', NULL, '0', NULL);

找到插入后的attribute_id,再插入到catalog_eav_attribute

INSERT INTO catalog_eav_attribute (attribute_id, is_global, is_visible, is_searchable, is_filterable, is_comparable, is_visible_on_front, is_html_allowed_on_front, is_used_for_price_rules, is_filterable_in_search, used_in_product_listing, used_for_sort_by, apply_to, is_visible_in_advanced_search, position, is_wysiwyg_enabled, is_used_for_promo_rules, is_required_in_admin_store, is_used_in_grid, is_visible_in_grid, is_filterable_in_grid, search_weight, additional_data) VALUES (你找到的attribute_id, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, "simple, virtual, bundle, downloadable, configurable", 1, 0, 0, 0, 0, 0, 0, 0, 1, NULL);

https://github.com/magento/magento2/issues/18134

31, 2.3.0版本后台上传logo报错 A technical problem with the server created an error

A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later.

这是2.3.0的bug,在2.3.1里修复了。
我们需要修改vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml这个文件。
fileUploader改成imageUploader

 <fieldset name="header">
            <settings>
                <level>1</level>
                <collapsible>true</collapsible>
                <label translate="true">Header</label>
            </settings>
            <field name="header_logo_src" formElement="imageUploader">
                <settings>
                    <label translate="true">Logo Image</label>
                    <componentType>imageUploader</componentType>
                </settings>

32, 后台保存产品报错 Column 'entity_id' cannot be null

magento2 SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entity_id' cannot be null, query was: INSERT INTO catalog_product_entity VALUES (?, ?, ?, ?, ?, ?, ?, ?)

这是数据库catalog_product_entity表出问题了,要把entity_id字段改成自增(auto increment)。
因为有其他表都relation这个entity_id字段,需要把其他关联表的relation删掉,才能修改自增(auto increment)。

33, php7.2报错 Cannot adopt OID in UCD-SNMP-MIB

Cannot adopt OID in UCD-SNMP-MIB: Cannot adopt OID in LM-SENSORS-MIB: lmTempSensorsValue

magento 2.3.x / php 7.2版本需要安装snmp扩展,以及安装snmp-mibs-downloader软件包

sudo apt-get install php7.2-snmp
sudo apt-get install snmp-mibs-downloader

34,composer安装报错 You must be using the interactive console to authenticate

[Composer\Downloader\TransportException]
The 'https://repo.magento.com/packages.json' URL required authentication.
You must be using the interactive console to authenticate

这是身份验证密钥失效了,需要重新验证下。
在项目根目录,输入命令:

composer update

根据提示,输入Magento密钥即可

35,2.3.0里报错 Cannot process definition to array for type tinytext

升级到2.3.0后,执行php bin/magento setup:upgrade会报错

Cannot process definition to array for type tinytext

这多半是因为你第三方插件里的表字段为tinytext类型,导致m2无法处理,需要把tinytext改成text类型。
那如何知道是哪个表哪个字段呢?
先打开文件

vim vendor/magento/framework/Setup/Declaration/Schema/Db/DefinitionAggregator.php

找到fromDefinition(),添加调试代码

public function fromDefinition(array $data)
    {
        $type = $data['type'];
        if (!isset($this->definitionProcessors[$type])) {
            echo "<pre>";
            print_r($data); exit();

            throw new \InvalidArgumentException(
                sprintf("Cannot process definition to array for type %s", $type)
            );
        }

        $definitionProcessor = $this->definitionProcessors[$type];
        return $definitionProcessor->fromDefinition($data);
    }

再执行php bin/magento setup:upgrade 就会出现具体的信息了

找到表和字段后 去数据库里修改下字段类型就ok了

36,v2.3.0里报错 Class Magento\Email\Model\Source\Variables does not exist

Compilation was started.
Area configuration aggregation... 5/7 [====================>-------] 71% 25 secs 248.0 MiB
In ClassReader.php line 35:
Class Magento\Email\Model\Source\Variables does not exist

这是因为Magento\Email\Model\Source\Variables这个类在v2.3.0里已经废弃了,用\Magento\Variable\Model\Source\Variables取代了。
所以,在服务器里搜索含有Magento\Email\Model\Source\Variables的文件,修改成Magento\Variable\Model\Source\Variables就行

//grep 搜索
grep -irn 'Magento\\Email\\Model\\Source\\Variables' app

37,后台sitemap generation生成的sitemap.xml无法访问 404 not found

因为nginx.conf.sample里访问的根目录是pub/,如果你的sitemap.xml没有放在pub/下面,就访问不到。
所以需要在Sitemap编辑页面,改下Path就行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值