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
In Laravel 11.15.0, #51373 introduced the ability to add / drop foreign keys in SQLite, by re-creating the table and copying all data.
However, I run into an error when the table being altered includes a JSON column with JSON_ARRAY() as default value. The error is something like:
SQLSTATE[HY000]: General error: 1 near "(": syntax error (Connection: sqlite, SQL: create table "__temp__items" ("id" integer primary key autoincrement not null, "flags" text not null default JSON_ARRAY(), "item_id" integer, foreign key("item_id") references "items"("id")))
The issue is that the SQL query the column definition should be something like "column_name" text not null default (JSON_ARRAY())), while the query executed has "flags" text not null default JSON_ARRAY()) (without the brackets). This results in a syntax error.
Steps To Reproduce
Create a table with a JSON column with (JSON_ARRAY()) as default value:
Laravel Version
11.22.0
PHP Version
8.3.6
Database Driver & Version
SQLite 3.45.1 for Linux on amd64
Description
In Laravel 11.15.0, #51373 introduced the ability to add / drop foreign keys in SQLite, by re-creating the table and copying all data.
However, I run into an error when the table being altered includes a JSON column with
JSON_ARRAY()
as default value. The error is something like:The issue is that the SQL query the column definition should be something like
"column_name" text not null default (JSON_ARRAY()))
, while the query executed has"flags" text not null default JSON_ARRAY())
(without the brackets). This results in a syntax error.Steps To Reproduce
Create a table with a JSON column with
(JSON_ARRAY())
as default value:Alter the table to add a foreign key constraint:
Running the second migration results in an error like:
Under the hood, the first migration execute the following SQL statement:
while the second migration executes:
The issue is that the second statement includes
JSON_ARRAY()
instead of(JSON_ARRAY())
.As a comparison, manually running the
.schema items
in SQLite we get:The text was updated successfully, but these errors were encountered: