# 常見問題 二
## 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` 就會出現具體的信息了

找到表和字段后 去數據庫里修改下字段類型就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`就行。

- 序言
- 全面解讀Magento2
- Magento2簡介
- Magento2特點
- Magento2目錄結構
- Magento2語法講解
- 運行原理剖析
- 開啟Magento2之旅
- 安裝Magnto2
- 購買阿里云服務器(Ubuntu系統)
- 安裝和配置Nginx/PHP/PHP-FPM
- 配置Mysql并創建數據庫
- 配置Nginx虛擬主機
- 安裝和配置Magento2
- 導入演示數據
- 手把手教你創建git代碼庫
- 續外篇-購買AWS服務器
- 續外篇-Mac下安裝LNMP
- 續外篇-安裝phpmyadmin
- 如何升級php版本
- 使用Magento2
- 創建多網店多域名以及安裝中文語言包
- 創建獨立cms頁面
- 創建分類和產品
- 創建產品屬性
- 創建優惠券
- 導入產品csv
- 下單/發票/發貨/退貨
- M2常用命令
- 如何安裝主題
- 如何安裝插件
- 如何使用API
- 常見問題
- 常見問題 二
- 常見問題 三
- 常見問題 四
- 常見問題 五
- Magento2主題
- 主題框架詳解
- Layout文件詳解
- M2里的JS
- 主題實戰
- 前期準備工作
- 完成首頁
- 重寫分類頁面
- 錦囊妙計
- 產品詳情頁面講解
- 購物車頁面講解
- 支付頁面講解
- 主題修改記錄
- 關于主題的一些學員問答
- Magento2插件
- 插件框架詳解
- XML配置說明
- 插件實戰
- 準備工作
- 寫代碼
- 調試
- 難點解析
- 插件升級
- 插件修改記錄
- 擴展閱讀
- 如何創建cron任務和功能
- 發送郵件(帶附件)
- 如何在代碼里創建屬性
- Magento2線上部署
- 基本流程
- 配置Redis
- 配置Varnish+SSL
- Varnish配置教程(2020年修訂版)
- Paypal設置
- 一些優化
- Magento2 版本升級
- v2.3.0版本填坑指南
- v2.4.x升級指南
- 配置nginx pagespeed模塊進行加速
- M1數據庫遷移到M2指南
- 安裝配置Elasticsearch
- Magento2常用工具
- 網站測速分析工具
- 在線創建插件模塊
- M2后臺可視化編輯器里的標簽變量
- 遇到問題,我該怎么做
- 常用代碼
- SEO在線分析工具
- 本地用xdebug遠程調試mgtdev2服務器的項目
- 后續之路