Skip to content
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

team_id db migration fails for SQLite #130

Closed
marvinscham opened this issue Feb 4, 2024 · 1 comment
Closed

team_id db migration fails for SQLite #130

marvinscham opened this issue Feb 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@marvinscham
Copy link

Hi! I'm self-hosting Input with SQLite via docker compose. Updating from v1.7.0 to v1.8.1 ran the following migration unsuccessfully which in turn broke most features of the site since the team_id column can't be queried.

input  |   2023_12_01_145224_add_team_id_to_forms ............................ 1ms FAIL
input  | [2024-02-04 17:03:59] production.ERROR: SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL (Connection: sqlite, SQL: alter table "forms" add column "team_id" integer not null) {"exception":"[object] (Illuminate\\Database\\QueryException(code: HY000): SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL (Connection: sqlite, SQL: alter table \"forms\" add column \"team_id\" integer not null) at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:801)

Looks like either the column needs to be nullable during its creation or a non-null DEFAULT needs to be added for the SQLite version of this call:

Schema::table('forms', function (Blueprint $table) {
$table->foreignIdFor(Team::class)->after('user_id');
});

Quick fix that did it for me: re-running the command with a default value specified, 1 being the ID of the default team of my instance:

  • docker exec -it input sh
  • sqlite3 storage/database.sqlite
  • alter table "forms" add column "team_id" integer not null default 1;
  • insert into migrations VALUES (39, "2023_12_01_145224_add_team_id_to_forms", 1);

The last step makes sure Input won't try to re-run the migration, which would fail due to duplicate columns.

@PhilReinking
Copy link
Contributor

Hey Marvin, thank you so much for your report and the solution you found. I will take a look into it. I think we would need to add special migrations for the sqlite driver. Not sure right now :)

@PhilReinking PhilReinking added the bug Something isn't working label Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants