# 常见问题 二 ## 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配置文件,添加 ``` 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_open`, `exec` 这几个函数也需要从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` 就会出现具体的信息了 ![](https://box.kancloud.cn/e1eedb3d53f03c3eccbe2d2cd784481c_558x336.png) 找到表和字段后 去数据库里修改下字段类型就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`就行。 ![](https://box.kancloud.cn/906a3ecee7026eda1fb37d0ebda47a04_1052x355.png)