Schemas not working in SQLite anymore since ORM 3 #7326

Closed
opened 2026-01-22 15:49:58 +01:00 by admin · 4 comments
Owner

Originally created by @ThomasLandauer on GitHub (Feb 13, 2024).

Bug Report

Q A
BC Break yes
Version 3.0.0

Summary

In https://github.com/doctrine/dbal/pull/4805 the schema emulation for SQLite was removed from DBAL. Could it be that it was forgotten to integrate this into the ORM (as suggested by that PR)?

How to reproduce

I created a migration:

bin/console make:migration

It has lines such as:

$this->addSql('CREATE TABLE myschema.mytable (...)');

(This used to be CREATE TABLE myschema__mytable in the previous versions)

When I run it, I'm getting:

An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1 unknown database myschema

The table in the entity is defined like this:

#[ORM\Table(schema: 'myschema')]
Originally created by @ThomasLandauer on GitHub (Feb 13, 2024). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes | Version | 3.0.0 #### Summary In https://github.com/doctrine/dbal/pull/4805 the schema emulation for SQLite was removed from DBAL. Could it be that it was forgotten to integrate this into the ORM (as suggested by that PR)? #### How to reproduce I created a migration: ```bash bin/console make:migration ``` It has lines such as: ```php $this->addSql('CREATE TABLE myschema.mytable (...)'); ``` (This used to be `CREATE TABLE myschema__mytable` in the previous versions) When I run it, I'm getting: > An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1 unknown database myschema The table in the entity is defined like this: ```php #[ORM\Table(schema: 'myschema')] ```
admin closed this issue 2026-01-22 15:49:58 +01:00
Author
Owner

@derrabus commented on GitHub (Feb 13, 2024):

You need to "create" that schema by attaching an additional SQLite file. That's how schemas work in SQLite, see https://www.sqlite.org/lang_attach.html

You can do so using a custom middleware for example. Alternatively, we could think about adding a config param to DBAL for configuring the schemas.

Closing because there's nothing we can do about it in the ORM.

@derrabus commented on GitHub (Feb 13, 2024): You need to "create" that schema by attaching an additional SQLite file. That's how schemas work in SQLite, see https://www.sqlite.org/lang_attach.html You can do so using a custom middleware for example. Alternatively, we could think about adding a config param to DBAL for configuring the schemas. Closing because there's nothing we can do about it in the ORM.
Author
Owner

@c33s commented on GitHub (Feb 29, 2024):

@derrabus had the same issue. any chance to bring the old behavior back? it is quite a common use case to use sqlite on the CI while using postgres in production. hope it is ok if i comment here as bringing back the old behavior using attributes would be part of the ORM would it?

You can do so using a custom middleware for example

shifting the handling to the userspace is quite sad as the feature worked perfectly before. would you mind to share your thoughts how this can be done in a middleware?

Alternatively, we could think about adding a config param to DBAL for configuring the schemas.

would you mind to explain that a little bit. how would it work to map specific entities to specific schemas? do you think of configuring it like having multiple database?

@c33s commented on GitHub (Feb 29, 2024): @derrabus had the same issue. any chance to bring the old behavior back? it is quite a common use case to use sqlite on the CI while using postgres in production. hope it is ok if i comment here as bringing back the old behavior using attributes would be part of the ORM would it? > You can do so using a custom middleware for example shifting the handling to the userspace is quite sad as the feature worked perfectly before. would you mind to share your thoughts how this can be done in a middleware? > Alternatively, we could think about adding a config param to DBAL for configuring the schemas. would you mind to explain that a little bit. how would it work to map specific entities to specific schemas? do you think of configuring it like having multiple database?
Author
Owner

@derrabus commented on GitHub (Feb 29, 2024):

@derrabus had the same issue. any chance to bring the old behavior back?

Convince me that I want to maintain an emulation of a feature that all supported database systems support natively. Otherwise, no chance.

it is quite a common use case to use sqlite on the CI while using postgres in production.

Yes, and nobody wants to stop you from doing that.

would you mind to share your thoughts how this can be done in a middleware?

I've posted a link on how additional databases can be attached in SQLite. The DBAL middleware system is also documented.

do you think of configuring it like having multiple database?

Yes.

@derrabus commented on GitHub (Feb 29, 2024): > @derrabus had the same issue. any chance to bring the old behavior back? Convince me that I want to maintain an emulation of a feature that all supported database systems support natively. Otherwise, no chance. > it is quite a common use case to use sqlite on the CI while using postgres in production. Yes, and nobody wants to stop you from doing that. > would you mind to share your thoughts how this can be done in a middleware? I've posted a link on how additional databases can be attached in SQLite. The DBAL middleware system is also documented. > do you think of configuring it like having multiple database? Yes.
Author
Owner

@mvorisek commented on GitHub (Mar 10, 2024):

The solution is to add schema/ATTACH support to DBAL, ie. to support it in SQLite DBAL platform and manager. I can implement under on paid basis as I am interested in the schema support for atk4/data project.

@mvorisek commented on GitHub (Mar 10, 2024): The solution is to add schema/ATTACH support to DBAL, ie. to support it in SQLite DBAL platform and manager. I can implement under on paid basis as I am interested in the schema support for atk4/data project.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7326