简体   繁体   English

在 Heroku 上打开 Symfony 应用程序时出现 SQLite 错误

[英]SQLite error opening Symfony app on Heroku

Error itself:错误本身:

2021-07-20T23:43:33.993462+00:00 app[web.1]: [20-Jul-2021 23:43:33 UTC] [critical] Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "SQLite3Cache" from namespace "Doctrine\Common\Cache".
2021-07-20T23:43:33.993688+00:00 app[web.1]: Did you forget a "use" statement for another namespace?" at /app/src/Utils/FilesCache.php line 23

The file contents of "FilesCache.php" are similar to what's provided in Symfony's documentation here with a few additions. “FilesCache.php”的文件,内容类似于什么的Symfony的文档中提供了这里有一些补充。

<?php
namespace App\Utils;

use App\Utils\Interfaces\CacheInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\SQLite3Cache;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;


class FilesCache implements CacheInterface
{
    public $cache;

    public function __construct()
    {
        //this is error line 23
        $provider = new SQLite3Cache(new \SQLite3(__DIR__ . '/cache/data.db'), 'TableName');

        $this->cache =  new TagAwareAdapter(
            new DoctrineAdapter(
                $provider,
                $namespace = '',
                $defaultLifetime = 0
            )
        );
    }
}

I've added both "pdo_sqlite" and "sqlite3" extensions to "composer.json".我已将“pdo_sqlite”和“sqlite3”扩展名添加到“composer.json”。 Composer update runs without issue. Composer 更新运行没有问题。

I'm committing both the "composer.json" and "composer.lock" before pushing the local project repo to Heroku, which runs without issue as well and shows that both extensions are added.在将本地项目存储库推送到 Heroku 之前,我同时提交了“composer.json”和“composer.lock”,Heroku 运行也没有问题,并显示添加了两个扩展。

remote: -----> Installing platform packages...
remote:        - php (8.0.8)
remote:        - ext-intl (bundled with php)
remote:        - ext-pdo_sqlite (bundled with php)
remote:        - ext-sqlite3 (bundled with php)
remote:        - composer (2.1.3)
remote:        - apache (2.4.48)
remote:        - nginx (1.20.1)

I know that SQLite isn't the proper choice for a production database, I'm following a course and I'd like to continue using what's provided from it.我知道 SQLite 不是生产数据库的正确选择,我正在学习一门课程,我想继续使用它提供的内容。

Thank you in advance for any help!预先感谢您的任何帮助!

As mentioned in the comments, the problem was the deprecation of doctrine/cache.正如评论中提到的,问题是学说/缓存的弃用。 I switched to a PDOAdapter and this fixed the issue.我切换到 PDOAdapter,这解决了这个问题。

 <?php
        namespace App\Utils;
        
        use App\Utils\Interfaces\CacheInterface;
        use Symfony\Component\Cache\Adapter\TagAwareAdapter;
        use Symfony\Component\Cache\Adapter\PdoAdapter;
        use Doctrine\DBAL\Driver\Connection;
        
        
        class FilesCache implements CacheInterface
        {
            public $cache;
    
            public function __construct()
            {
                $connection = \Doctrine\DBAL\DriverManager::getConnection([
                    'url' => 'sqlite:////%kernel.project_dir%/var/cache/data.db'
                ]);
        
                $this->cache =  new TagAwareAdapter(
                    new PdoAdapter(
                        $connection,
                        $namespace = '',
                        $defaultLifetime = 0
                    )
                );
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM