sinamics/ztnet

[Bug]: prisma migration failed

Closed this issue ยท 4 comments

๐Ÿ› Describe the Bug

Hi :)

  1. At the command:
$ npx prisma migrate deploy
Warning Precompiled engine files are not available for freebsd14. Read more about building your own engines at https://pris.ly/d/build-engines
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "ztnet", schema "public" at "127.0.0.1:5432"

36 migrations found in prisma/migrations

Applying migration `20240827062445_device_notification`
Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 20240827062445_device_notification

Database error code: 23502

Database error:
ERROR: column "userAgent" of relation "UserDevice" contains null values

DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E23502), message: "column \"userAgent\" of relation \"UserDevice\" contains null values", detail: None, hint: None, position: None, where_: None, schema: Some("public"), table: Some("UserDevice"), column: Some("userAgent"), datatype: None, constraint: None, file: Some("tablecmds.c"), line: Some(6093), routine: Some("ATRewriteTable") }
  1. Second attempt:
$ npx prisma migrate deploy
Warning Precompiled engine files are not available for freebsd14. Read more about building your own engines at https://pris.ly/d/build-engines
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "ztnet", schema "public" at "127.0.0.1:5432"

36 migrations found in prisma/migrations

Error: P3009

migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
The `20240827062445_device_notification` migration started at 2024-08-27 09:12:18.281372 UTC failed

  1. Roll back:
$ npx prisma migrate resolve --rolled-back "20240827062445_device_notification"
Warning Precompiled engine files are not available for freebsd14. Read more about building your own engines at https://pris.ly/d/build-engines
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "ztnet", schema "public" at "127.0.0.1:5432"

Migration 20240827062445_device_notification marked as rolled back.

What did I miss?... ;)

๐Ÿ” Steps to Reproduce

๐ŸŒ Browser

Firefox

๐Ÿ”ง Deployment Type

  • Docker
  • Standalone

โœจ Expected Behavior

No response

๐Ÿ“‹ ZTNET Logs

No response

๐Ÿ–ผ Screenshots

No response

This error occurs because you're working with the main branch instead of a specific release tag. The UserDevice model already exists in your database, but i have update the same migration with a new userAgent column.

you can try npx prisma migrate dev, i think you will get warning, but might be able to execute the migration.

No luck ;)

$ npx prisma migrate dev
Warning Precompiled engine files are not available for freebsd14. Read more about building your own engines at https://pris.ly/d/build-engines
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "ztnet", schema "public" at "127.0.0.1:5432"

Applying migration `20240827062445_device_notification`
Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 20240827062445_device_notification

Database error code: 23502

Database error:
ERROR: column "userAgent" of relation "UserDevice" contains null values

DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E23502), message: "column \"userAgent\" of relation \"UserDevice\" contains null values", detail: None, hint: None, position: None, where_: None, schema: Some("public"), table: Some("UserDevice"), column: Some("userAgent"), datatype: None, constraint: None, file: Some("tablecmds.c"), line: Some(6093), routine: Some("ATRewriteTable") }

Well, maybe I can do some changes using phpPgAdmin?

OK, fixed by hand in phpPgAdmin :)