symfonydoctrine-ormapi-platform.com

SQLite with Doctrine causes "getCreateSequenceSQL is not supported by platform."


I am using a modified version of the API Platform Symfony environment. Since Docker is not working for me right now, I'm falling back to using SQLite as the database provider.

I uncomment the following line in my .env file:

DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"

... and run bin/console doctrine:database:create, which gives me a nice success message:

Created database /home/patrickmaynard/coding-projects/tag-jesus/api/var/data.db for connection named default

So far, so good.

Now I run bin/console doctrine:schema:create, and get the following:

In Exception.php line 20:
                                                                                                            
  Operation 'Doctrine\DBAL\Platforms\AbstractPlatform::getCreateSequenceSQL' is not supported by platform. 

Based on something I saw in another question/answer, I got rid of all my migrations and generated a new migration that covered my entity changes. That did not make any difference.

Any idea what might be causing this?


Solution

  • The issue is coming from this line. This means that the Doctrine DBAL doesn't support sequences on the current platform. MySQL and Sqlite doesn't have built-in function to create Sequences but provides an alternative in the form of the AUTO_INCREMENT column.

    My Guess is you are using PostgreSQL or Oracle SQL in Docker which supports sequences but now switching to SQLite is throwing this error.

    Solution:

    Not sure how you are dealing with Sequences in your migration files. So one solution is to check if the platform supports sequences and do any sequence related operations.

        ...
        if ($this->platform->supportsSequences()) {
            ...
        }
        ...
    

    Another solution is, you can extend the SqlitePlatform and write custom sequence generator functions. You need to override a few methods from AbstractPlatform.

    Check the documentation at the end of this page on how to override the platforms.