question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not validate `default` for `@db.MediumText` as it is not allowed in MySQL

See original GitHub issue

Problem

If setting a default value on a field with @db.MediumText (mysql) running migrate after a format and generate errors with shadow db error and migration fail and then have to reset database and lose all the data and thinking/suggesting that prisma format should catch this.

model Stuff {
  id                    String @id
// creates unrecoverable migration issue - @db.MediumText @default("") 
  label                 String @db.MediumText @default("")
}

Running prisma generate prisma format all seems fine, then run prisma migrate and explodes and have to accept nuke of the db and start over.

My current solution when i encounter unrecoverable migration errors or tokyo drift like this is to use mysql workbench export wizard to export each table in db, but this won’t be sustainable as # of tables increase / go to prod etc. Maybe there is a way to backup whole db and force a migration or such.

Suggested solution

prisma format should strip @default("") from any keys that are String @db.MediumText

Alternatives

tbd

Additional context

mysql 8.0 and node v14.15.3

@prisma/client”: “^2.22.1”, “express”: “^4.17.1”, “typescript”: “^4.2.3”

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pantharshit00commented, May 27, 2021
code/reproductions/issue-7080 is 📦 v1.0.0 via  v14.17.0
❯ npx prisma migrate dev
Environment variables loaded from prisma\.env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "issue_7080" at "localhost:3306"

MySQL database issue_7080 created at localhost:3306

√ Enter a name for the new migration: ... init
Error: P3018

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

Migration name: 20210527170531_init

Database error code: 1101

Database error:
BLOB, TEXT, GEOMETRY or JSON column 'label' can't have a default value

I can reproduce this and I think we should disallow this in the schema level validator rather than stripping this in format. Marking this as a confirmed bug.

1reaction
do4grcommented, Jan 12, 2022

While migrate cannot persist the default value on the db level, the client will still be able to write the value to the database in cases where no value is provided in the query. Rejecting this via a validation would break this functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't a text column have a default value in MySQL?
Even trying to use the latest version of phpMyAdmin to extract the database, it doesn't report a default for the text column in...
Read more >
11.3.4 The BLOB and TEXT Types - MySQL :: Developer Zone
A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB , BLOB...
Read more >
13.1.9 ALTER TABLE Statement - MySQL :: Developer Zone
Specifying a non-default value for this clause enables you to require a certain amount of concurrent access or exclusivity during the alter operation,...
Read more >
9.3 Keywords and Reserved Words - MySQL :: Developer Zone
Keywords are words that have significance in SQL. Certain keywords, such as SELECT , DELETE , or BIGINT , are reserved and require...
Read more >
13.1.8 ALTER TABLE Statement - MySQL :: Developer Zone
These keywords are no longer supported; their use causes a syntax error. MySQL NDB Cluster 7.5 (and later) supports online operations using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found