[Bug]: prisma migration failed
Closed this issue ยท 4 comments
tinola commented
๐ Describe the Bug
Hi :)
- 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") }
- 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
- 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
sinamics commented
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.
sinamics commented
you can try npx prisma migrate dev
, i think you will get warning, but might be able to execute the migration.
tinola commented
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?
tinola commented
OK, fixed by hand in phpPgAdmin :)