27

所以我已经让 magento 2 运行良好,我什至开始使用我自己的主题,但是我在安装 magento 后尝试安装示例数据。它在终端中返回了“未设置区号:”,下面是我的步骤。

bin/magento sampledata:deploy    
composer update

返回:

Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing magento/module-catalog-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-bundle-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-widget-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-customer-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/sample-data-media (100.0.3)
    Downloading: 100%         

  - Installing magento/module-theme-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-cms-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-catalog-rule-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-sales-rule-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-review-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-tax-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-grouped-product-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-downloadable-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-msrp-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-sales-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-product-links-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-configurable-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-wishlist-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-swatches-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-offline-shipping-sample-data (100.0.3)
    Downloading: 100%         

Writing lock file
Generating autoload files

然后我运行:

bin/magento setup:upgrade

我在下面的屏幕截图中看到了以下错误,我似乎无法在网上找到其他有相同错误的人。

区号终端窗口未设置:

  [Magento\Framework\Exception\SessionException]                       
  Area code not set: Area code must be set before starting a session.  

  [Magento\Framework\Exception\LocalizedException]  
  Area code is not set    

现在我的法师安装不起作用 - 错误返回:

请升级您的数据库:从 Magento 根目录运行“bin/magento setup:upgrade”。

我不能这样做,因为它返回和错误,任何帮助都会很棒。

4

6 回答 6

49

有同样的问题并且能够解决它。

尝试先运行此命令:

php bin/magento sampledata:reset

然后重新运行:

php bin/magento setup:upgrade

如果您遇到内存耗尽错误(我遇到过),请尝试添加-dmemory_limit=6G您的setup:upgrade命令。

php -dmemory_limit=6G bin/magento setup:upgrade
于 2016-02-11T03:42:48.073 回答
6

尝试先运行此命令:

php bin/magento app:config:import

然后清除缓存并运行 setup:upgrade

于 2018-11-06T06:35:15.543 回答
2

在安装示例数据并再次使用 composer 卸载几个选定的示例数据模块后,我在 Magento 2.4.2 上遇到了这个问题。为了解决这个问题,我手动更改了 app\etc\config.php,将示例数据不需要的那些扩展设置为 0 而不是 1(我试图使用 CLI 命令删除)。

于 2021-04-15T07:19:17.070 回答
1

安装 Magento 2.0.7 后我遇到了同样的问题,然后尝试安装示例数据。

Module 'Magento_ConfigurableSampleData':  [Magento\Framework\Exception\SessionException]  Area code not set: Area code must be set before starting a session.

我也尝试重置(php bin/magento sampledata:reset),但还有另一个错误:

  [Zend_Db_Statement_Exception]
  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot be null, query was: INSERT INTO `setup_module` (`modul
  e`, `data_version`) VALUES (?, ?)

因为我的设置是基于 CLI (php bin/magento setupinstall --...),所以我不知道为什么。直到在网站前面再次设置它。在setup php检查过程中,出现php值错误:

Your PHP Version is 5.6.18, but always_populate_raw_post_data = 0. $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0. This will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1. If you need more help please call your hosting provider.

因此,在 php.ini 或 .htaccess 中设置 always_populate_raw_post_data = -1 之后。(如果需要,重新启动 php 或 php-fpm)。然后,示例数据已安装并运行良好。

希望这些步骤对某人有所帮助。

于 2016-06-21T21:38:43.470 回答
1

我有同样的问题并且能够解决

仅对 magento (2.4.1) 尝试此命令

php -dmemory_limit=5G bin/magento cache:flush
php -dmemory_limit=5G bin/magento sampledata:reset
php -dmemory_limit=5G bin/magento setup:upgrade

为 magento (2.4.2+) 尝试这个命令 在任何扩展中搜索 setAreaCode() 方法的用法,并检查它们是从哪里调用的。

替换代码

protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->appState->setAreaCode('frontend');
}

经过

protected function execute(InputInterface $input, OutputInterface $output)
{
try{
    $output->setDecorated(true);
    $this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
       // do nothing
   }
}

交替使用核心\Magento\Framework\App\State::emulateAreaCode方法来临时设置区号:

$self = $this;
   try {
       $this->appState->emulateAreaCode('frontend', function () use ($self) {
           // operations
       });
   } catch (\Exception $exception) {
       // handle exception
   }
于 2021-02-18T06:54:30.373 回答
-2

我遇到的关于这个特定错误的唯一问题是人们从以前版本的 Magento 2 beta 更新。您可以在 Github 上的 Magento 2 repo 问题跟踪器下阅读有关此内容的所有详细信息:安装时未设置区号:升级 #1529

总之,开发人员将升级说明更改为以下内容:

基本上,您从卸载开始,但不运行 setup:upgrade。相反,更新代码,作曲家更新,再次安装。

他们参考了这篇关于 Magento 的文章进行了更多解释。

现在我不知道这是否也能解决你的错误,但它似乎是同一个问题。此外,尽管 Magento 2 允许在安装后安装示例数据,但已知它比从一开始就安装更麻烦。以下是 Mageto 提供的一些资源,您可能需要查看这些资源以确保您做的所有事情都正确:

也有预感......(见编辑)......尝试改回原来的 Luma 主题,看看是否有区别。

编辑
预感我的意思是我有一个类似的大问题发生了,我从来没有足够关心它为什么会导致它,但是切换回默认主题并更新解决了我所有的问题。然后我再次切换回我自己的主题,从那以后它就再也没有问题了。

于 2016-02-07T03:30:42.187 回答