Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostrgreSQL 15 with Symfony 6.4 ID generation deprecation - SEQUENCE for Doctrine\DBAL\Platforms\PostgreSqlPlatform #1740

Closed
Mepcuk opened this issue Jan 7, 2024 · 4 comments

Comments

@Mepcuk
Copy link

Mepcuk commented Jan 7, 2024

I have deprecation warning as below. But how to fix it?

13:32:41 INFO      [deprecation] User Deprecated: Relying on non-optimal defaults for ID generation is deprecated, and IDENTITY
results in SERIAL, which is not recommended.
Instead, configure identifier generation strategies explicitly through
configuration.
We currently recommend "SEQUENCE" for "Doctrine\DBAL\Platforms\PostgreSqlPlatform", so you should use
$configuration->setIdentityGenerationPreferences([
    "Doctrine\DBAL\Platforms\PostgreSqlPlatform" => ClassMetadata::GENERATOR_TYPE_SEQUENCE,
]); (ClassMetadataFactory.php:751 called by ClassMetadataFactory.php:625, https://github.com/doctrine/orm/issues/8893, package doctrine/orm) ["exception" => ErrorException { …}]
PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 18221200 bytes) in /var/www/vendor/doctrine/dbal/src/Driver/PDO/Result.php on line 103
@Mepcuk
Copy link
Author

Mepcuk commented Jan 7, 2024

Found solution -> in your Entity's id field need to specify strategy 'SEQUENCE'

#[ORM\Entity(repositoryClass: WebpageRepository::class)]
#[ORM\Table(name: '`webpage`')]
class Webpage
{
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'SEQUENCE')]
    #[ORM\Column]
    private ?int $id = null;
....

@Mepcuk Mepcuk changed the title PostrgreSQL 15 in Symfony 6.4 deprecation PostrgreSQL 15 with Symfony 6.4 ID generation deprecation - SEQUENCE for Doctrine\DBAL\Platforms\PostgreSqlPlatform Jan 7, 2024
@Mepcuk
Copy link
Author

Mepcuk commented Jan 7, 2024

@Mepcuk Mepcuk closed this as completed Jan 7, 2024
@DannyvdSluijs
Copy link

@Mepcuk Are your sure? I'm experiencing the same issue and based on the code in the ClassMetadataFactory on line 750 (src) it always throws an deprecation.

This is also what I experience when trying different values. And as far as I can see this library doesn't support the setIdentityGenerationPreferences method yet.

As a side remark, one thing I found is that this deprecation only happens when an association mapping is part of the entity.

@TeLiXj
Copy link

TeLiXj commented Jan 22, 2024

I'm with @DannyvdSluijs, this bundle can't set the setIdentityGenerationPreferences and entities generated by Symfony Maker don't use any default strategies. To fix it you can override the default config using compiler pass in the src\Kernel.php

<?php

namespace App;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\{Compiler\CompilerPassInterface, ContainerBuilder};
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel implements CompilerPassInterface
{
    use MicroKernelTrait;

    public function process(ContainerBuilder $container): void
    {
        $container
            ->getDefinition("doctrine.orm.configuration")
            ->addMethodCall("setIdentityGenerationPreferences", [[PostgreSQLPlatform::class => ClassMetadata::GENERATOR_TYPE_SEQUENCE]]);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants