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
When creating a table using Blueprint (migrations), $table->unique() is ineffective at specifying an unique index. This happens with the SQLite driver that we are using for _development.
Steps To Reproduce
Run php artisan make:migration create_products_table in a terminal
Write to ./database/migrations/*_create_products_table.php:
<?phpuseIlluminate\Database\Migrations\Migration;
useIlluminate\Database\Schema\Blueprint;
useIlluminate\Support\Facades\Schema;
returnnewclassextends Migration {
/** * Run the migrations. */publicfunctionup(): void
{
Schema::create('products', function (Blueprint$table) {
$table->id();
$table->string('code', 20);
$table->string('name', 50);
$table->timestamps();
$table->unique('code');
});
// Get the raw SQL query for SQLiteechoDB::select("SELECT sql FROM sqlite_master WHERE type='table' AND name='products'")[0]->sql;
}
/** * Reverse the migrations. */publicfunctiondown(): void
{
Schema::dropIfExists('products');
}
};
Run php artisan migrate
The creation query written to stdout does not include the specification of the unique index on the "code" column. Also, if you open the database using a SQLite client, the "code" column is not marked as unique. We expect the opposite.
Stdout: CREATE TABLE "products" ("id" integer primary key autoincrement not null, "code" varchar not null, "name" varchar not null, "created_at" datetime, "updated_at" datetime)
The text was updated successfully, but these errors were encountered:
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
laravel new bug-report --github="--public"
Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.
After investigating better, we have discovered that Blueprint creates a unique index in a separate table. In particular, you can list the indexes for the products table with the following statement: PRAGMA index_list('products');. Also, the driver enforces the unique constraint correctly.
We close the issue. Sorry for the false alarm and thanks for your time.
Laravel Version
10.39.0
PHP Version
8.3.1
Database Driver & Version
SQLite 3.40.0 for Windows 10 x64
Description
When creating a table using Blueprint (migrations), $table->unique() is ineffective at specifying an unique index. This happens with the SQLite driver that we are using for _development.
Steps To Reproduce
php artisan make:migration create_products_table
in a terminalphp artisan migrate
The creation query written to stdout does not include the specification of the unique index on the "code" column. Also, if you open the database using a SQLite client, the "code" column is not marked as unique. We expect the opposite.
Stdout:
CREATE TABLE "products" ("id" integer primary key autoincrement not null, "code" varchar not null, "name" varchar not null, "created_at" datetime, "updated_at" datetime)
The text was updated successfully, but these errors were encountered: