-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Tests broken after upgrade doctrine/dbal to 2.10.3 #34093
Comments
I have the same problem and spent some time investigating it. What happened is that I don't know why, but it seems that doctrine/dbal does not create indexes when creating a table with foreign keys, but when changing an existing table with foreign keys, it tries to remove some non-existent index. |
Can cofirm that, the doctrine/dbal@85a983c commit is the one that breaks it in dbal for sqlite, so it does not work after an upgrade from dbal v2.10.2 to v2.10.3 |
Facing a similar problem here also after upgrading, seems not directly laravel but PHP 7.4.8 |
Feel free to share your information on the Doctrine issue I created: doctrine/dbal#4243 |
@hakanersu there are 2 exceptions in the code: framework/src/Illuminate/Database/Connection.php Lines 670 to 672 in caec40e
The one that appears in your screenshots comes from Laravel, and is triggered by the one line 670 , that is issued by When posting an exception you should:
If you still have access to the stack trace of the second exception, please post it as text on the page linked by @taylorotwell above, it will be helpful 🙏 |
@uuf6429 was the table created with the latest version of |
Yes - this happens before running tests, when running migrations through artisan. The migrations are all based on laravel blueprint. |
Is this method used at any point, and if yes, is framework/src/Illuminate/Database/Schema/Blueprint.php Lines 537 to 550 in caec40e
Shouldn't that result in CREATE TABLE tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
account_id INTEGER NOT NULL,
user_id INTEGER DEFAULT NULL,
subject VARCHAR(255) NOT NULL COLLATE BINARY,
start_date DATETIME NOT NULL,
state INTEGER DEFAULT 0 NOT NULL,
task_type INTEGER DEFAULT 0 NOT NULL,
task_queue_id INTEGER NOT NULL,
created_by_type VARCHAR(255) DEFAULT NULL COLLATE BINARY,
created_by_id INTEGER DEFAULT NULL,
created_at DATETIME DEFAULT NULL,
updated_at DATETIME DEFAULT NULL,
content CLOB DEFAULT NULL COLLATE BINARY,
end_date DATETIME DEFAULT NULL,
- CONSTRAINT 0 FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE,
- CONSTRAINT 1 FOREIGN KEY (account_id) REFERENCES accounts (id) ON UPDATE NO ACTION ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
+ FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE,
+ FOREIGN KEY (account_id) REFERENCES accounts (id) ON UPDATE NO ACTION ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
) Note that this syntax does not even appear in SQlite's official doc about foreign keys Here is where that syntax might come from: https://github.com/doctrine/dbal/blob/f69c990e359931753232a81c3a1821a7ea060bfd/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2586-L2588 |
Here is the actual SQL created when I create a table with a foreign key using Laravel: create table "posts"
("id" integer not null primary key autoincrement,
"user_id" integer not null,
"body" varchar not null,
"created_at" datetime null,
"updated_at" datetime null,
foreign key("user_id") references "users"("id")) However, if I later try to use
|
When attempting to change the column, here is an array of SQL statements array:7 [
0 => "DROP INDEX IDX_885DBAFAA76ED395"
1 => "CREATE TEMPORARY TABLE __temp__posts AS SELECT id, user_id, body, created_at, updated_at FROM posts"
2 => "DROP TABLE posts"
3 => "CREATE TABLE posts (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, body CLOB NOT NULL COLLATE BINARY, CONSTRAINT 0 FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)"
4 => "INSERT INTO posts (id, user_id, body, created_at, updated_at) SELECT id, user_id, body, created_at, updated_at FROM __temp__posts"
5 => "DROP TABLE __temp__posts"
6 => "CREATE INDEX IDX_885DBAFAA76ED395 ON posts (user_id)"
] |
Thanks, it explains a lot! I didn't understand why we were reading information from @MyIgel contributed doctrine/dbal#4246 yesterday, and I think it fixes the "reading information from posts before dropping it" part. Can people here please test |
I installed it ( I still receive the same error:
Verified the change from that PR in my |
Ok so there are in facts 2 bugs? One with query number 0 and one with query number 3, and I think @MyIgel fixed the one with query number 3 with doctrine/dbal#4246 . No idea why the DBAL thinks there should be an index in addition to the foreign key yet. Will try the reproducer in doctrine/dbal#4243 (comment) later, but feel free to beat me to it, anyone. EDIT: Started an investigation here: doctrine/dbal#4243 (comment) |
By the way, a bit late, but I have a further suggestion (which worked in my case). Depending on how many laravel users have this problem, we could add the following to "conflict": {
"doctrine/dbal": "2.10.3"
}, |
For the moment I have this workaround/experiment that is ugly but works: greg0ire/dbal#3 |
@greg0ire this may be related as well or coincidence? |
Too early to tell, but it's possible that it's at least related to the same pull request. Thanks for linking to that, I will keep an eye on it. |
Adding |
A little context that might help, I learned recently that sqlite does not allow alter statements, so DBALs tend to recreate the table with the new structure. |
|
We have released the bugfix as 2.10.4, please confirm the bug is fixed and close this. |
Awesome, thanks. |
You're very welcome, sorry for the trouble actually, and thanks to the Laravel community for helping out with the reproducers, PRs and investigations :) |
@greg0ire no sorry needed. Thanks for all your work 👍 |
Description:
After upgrading from 7.25.0 to v7.27.0 tests getting broken. Im getting query exceptions when using DatabaseMigrations, RefreshDatabase at same time.
It seems to related to #34091
Downgrading
doctrine/dbal
from2.10.3
to2.10.2
fixes problem.Steps To Reproduce:
Upgrade 7.27.0 and create any basic test withDatabaseMigrations, RefreshDatabase
. If i use just one of them tests works fine.The text was updated successfully, but these errors were encountered: