You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have two migrations which in laravel/framework 11.14.0 run without issue, however in laravel/framework 11.15.0+ now return us the following error:
Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation:
1075 Incorrect table definition; there can be only one auto column and it must be defined
as a key (Connection: tenant, SQL: alter table `ticket_users` drop primary key)
The migrations concerned are as follows:
Create the table
<?phpuseIlluminate\Database\Migrations\Migration;
useIlluminate\Database\Schema\Blueprint;
useIlluminate\Support\Facades\Schema;
returnnewclassextends Migration
{
/** * Run the migrations. */publicfunctionup()
{
Schema::create('ticket_users', function (Blueprint$table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('ticket_id');
$table->unsignedBigInteger('user_id');
$table->unique(['ticket_id', 'user_id']);
$table->foreign('ticket_id')->references('id')->on('tickets')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
};
Update the table
<?phpuseIlluminate\Database\Migrations\Migration;
useIlluminate\Database\Schema\Blueprint;
useIlluminate\Support\Facades\Schema;
returnnewclassextends Migration
{
/** * Run the migrations. */publicfunctionup(): void
{
Schema::table(
'ticket_users',
function (Blueprint$table) {
$table->dropPrimary();
$table->bigInteger('id')->change();
$table->dropColumn('id');
}
);
Schema::table(
'ticket_users',
function (Blueprint$table) {
$table->primary(['ticket_id', 'user_id']);
}
);
}
};
Steps To Reproduce
If you run this migration first
<?phpuseIlluminate\Database\Migrations\Migration;
useIlluminate\Database\Schema\Blueprint;
useIlluminate\Support\Facades\Schema;
returnnewclassextends Migration
{
/** * Run the migrations. */publicfunctionup()
{
Schema::create('tickets', function (Blueprint$table) {
$table->bigIncrements('id');
});
Schema::create('users', function (Blueprint$table) {
$table->bigIncrements('id');
});
}
};
then run the two migrations in the issue described above, you'll get a MySql error
Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation:
1075 Incorrect table definition; there can be only one auto column and it must be defined
as a key (Connection: tenant, SQL: alter table `ticket_users` drop primary key)
If you do the same in 11.14.0, then it will run without issue.
I suspect it could be an issue which has arisen out of #51373
The text was updated successfully, but these errors were encountered:
@midnite81 on MySQL you can't drop the key if the column is auto incremental, so you should first drop the auto increment then drop its primary (just switch those 2 commands):
Schema::table('ticket_users', function (Blueprint$table) {
$table->bigInteger('id')->change(); // drop auto increment first$table->dropPrimary(); // then drop primary$table->dropColumn('id');
$table->primary(['ticket_id', 'user_id']);
});
Before 11.15, the change commands would always run at first, that's why you were not getting any error, but after 11.15, the commands compile in the real order.
However, dropping auto increment and primary seems redundant in your case, as you are eventually dropping the whole column, you may want to simplify this to:
Schema::table('ticket_users', function (Blueprint$table) {
// $table->bigInteger('id')->change(); // no need for this// $table->dropPrimary(); // no need for this either$table->dropColumn('id');
$table->primary(['ticket_id', 'user_id']);
});
Laravel Version
11.15.0
PHP Version
8.3.9
Database Driver & Version
8.0.37 MySql
Description
We have two migrations which in laravel/framework 11.14.0 run without issue, however in laravel/framework 11.15.0+ now return us the following error:
The migrations concerned are as follows:
Create the table
Update the table
Steps To Reproduce
If you run this migration first
then run the two migrations in the issue described above, you'll get a MySql error
If you do the same in 11.14.0, then it will run without issue.
I suspect it could be an issue which has arisen out of #51373
The text was updated successfully, but these errors were encountered: