-
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
Laravel 11 SQLite Migration Failure: after drop column: unknown column "XXXXXX" in foreign key definition #51318
Comments
Unlike So you may drop its index before dropping the column: Schema::table('sessions', function (Blueprint $table) {
$table->dropIndex(['user_id']);
$table->dropColumn('user_id');
}); |
Thanks @hafezdivandari |
That doesn’t work for me… The SQLite doc also say that the command will fail if |
@Gandhi11 in that case you'll have to drop the foreign constraint as well beforehand. |
@driesvints And how I am supposed to do that? Dropping foreign keys is not supported by the SQLite driver. |
Sorry, wasn't aware of that. @hafezdivandari what's your take here? |
I haven't tested this, but you may try to temporary disable foreign key constraints and see if it works: Schema::withoutForeignKeyConstraints(function () {
Schema::table('sessions', function (Blueprint $table) {
$table->dropIndex(['user_id']);
$table->dropColumn('user_id');
});
}); However, these limitions are related to SQLite, not Laravel. That's how |
@hafezdivandari unfortunately this doesn't work, I still receive an error on the foreignKey when the migration tries to drop the column.
The problem on the drop appear at the moment the foreignId is marked as constrained like so.
If there is no constrained, there is no problem. This wasn't a problem before when using doctrine/dbal since it was recreating the table without the constrained foreign. I also tried with |
I'm sorry, again, that's how SQLite works! The only thing comes to mind right now is to implement |
Thank you for your response. And yes I understand that it is how SQLite works but that edge case was handle before and always worked since Laravel 5 when using doctrine/dbal. I get that now since Laravel 11 it is using alter table to drop columns with SQLite 3.45 but it seems that it is causing something that was working to break. Do you know if it would be possible use doctrine/dbal for that edge case? |
I've been experiencing the same issue recently, so I'm bumping this issue, hoping for a solution! |
I'm preparing a PR, mostly done, hopefully we can fix this. |
You may check PR #51373, hopefully if it's merged you can do: Schema::table('sessions', function (Blueprint $table) {
$table->dropIndex(['user_id']);
$table->dropForeign(['user_id']);
$table->dropColumn('user_id');
});
// Or...
Schema::table('sessions', function (Blueprint $table) {
$table->dropIndex(['user_id']);
$table->dropConstrainedForeignId('user_id');
}); |
Not working with Laravel 11: - laravel/framework#51318 - laravel/framework#51373
fixes #1702 based on laravel/framework#51318 (comment) Signed-off-by: Mior Muhammad Zaki <[email protected]>
fixes #1702 based on laravel/framework#51318 (comment) Signed-off-by: Mior Muhammad Zaki <[email protected]>
Laravel Version
11.6.0
PHP Version
8.3.6
Database Driver & Version
SQLite 3.45.1
Description
In Laravel 11, running tests in memory using SQLite I receive this error when trying to drop a column that have a foreign key on it. That wasn't a problem before when using
doctrine/dbal
(#48864).Steps To Reproduce
user_id
column on thesessions
table like so:use RefreshDatabase;
in the defaultTestCase
classtest_the_application_returns_a_successful_response
.The text was updated successfully, but these errors were encountered: