Migrate: Deserializing the database migration failed

Created on 27 Mar 2020  ยท  5Comments  ยท  Source: prisma/migrate

Currently I have an npm prestart command that runs:
prisma2 migrate up --experimental && prisma2 generate

After updating to preview025 I'm getting the follow error from the prestart command:

> prisma2 migrate up --experimental
Error: Error in migration engine: Mar 27 11:00:19.001  INFO migration_engine: Starting migration engine RPC server git_hash="8814060fa684793b73d07dbfccd4b7777b3361ae"
Mar 27 11:00:19.010  INFO quaint::single: Starting a postgresql pool with 1 connections.
Mar 27 11:00:19.011  INFO tokio_postgres::connection: NOTICE: schema "public" already exists, skipping

And when running the migration command by itself I'm seeing this error instead:

โ•ฐโ”€ prisma2 migrate up --experimental
 ERROR  Oops, an unexpected error occured!
Error in migration engine.
Reason: [migration-engine/connectors/sql-migration-connector/src/lib.rs:237:9] Deserializing the database migration failed.: Error("unknown variant `0`, expected one of `VALUE`, `NOW`, `SEQUENCE`, `DBGENERATED`", 
line: 0, column: 0)
Please create an issue in the migrate repo with
your `schema.prisma` and the prisma2 command you tried to use ๐Ÿ™:
https://github.com/prisma/migrate/issues/new
Please help us improve Prisma 2 by submitting an error report.
Error reports never contain personal or other sensitive information.
Learn more: https://pris.ly/d/telemetry
โ”Œโ”€ Submit error report โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                                                                                                                                                                                 โ”‚
โ”‚ โฏ Yes            Send error report once                                                                                                                                                                         โ”‚
โ”‚   No             Don't send error report                                                                                                                                                                        โ”‚
โ”‚                                            

Heres my schema.prisma:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id              String       @id @default(cuid())
  externalID      String       @unique
  screen_name     String
  isSubscribed    Boolean      @default(false)
  isNewUser       Boolean      @default(true)
  profileImageUrl String
  name            String
  commitments     Commitment[]
  posts           Post[]
  createdAt       DateTime     @default(now())
}

model Post {
  id                String   @id @default(cuid())
  externalID     String   @unique
  createdAt         String
  deconstructedDate String
  text              String
  source            String
  tags              String[]
  media             Media[]
  author            User
}

model Commitment {
  id           String @id @default(cuid())
  text         String
  type         String
  duration     Int
  durationType String
  author       User
}

model Media {
  id             String  @id @default(cuid())
  post           Post
  externalID String  @unique
  imageUrl       String?
  videoUrl       String?
  type           String
}

Most helpful comment

Thanks, I've confirmed the following does not affect existing data in the database:

  • Delete prisma/migrations/ folder
  • Drop _Migration table
  • Create/Save a new initial migration
  • Run migrate up

This can probably be closed as wontfix as it's a relatively easy thing to work around during the preview phase.

All 5 comments

I have a similar issue once updated to p025, slightly different error though:

โฏ npx prisma2 migrate up --experimental
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
 ERROR  Oops, an unexpected error occured!
Error in migration engine.
Reason: [migration-engine/connectors/sql-migration-connector/src/lib.rs:237:9] Deserializing the database migration failed.: Error("un
known variant `nextval(\'\"_Migration_revision_seq\"\'::regclass)`, expected one of `VALUE`, `NOW`, `SEQUENCE`, `DBGENERATED`", line: 
0, column: 0)

Please create an issue in the migrate repo with
We successfully received the error report
To help us even more, please create an issue at https://github.com/prisma/prisma2/issues/new
mentioning the report id 2368.

Thanks a lot for your help! ๐Ÿ™

This is the current schema in the database as it relates to _Migration (pg_dump output):

CREATE TABLE public."_Migration" (
    revision integer NOT NULL,
    name text NOT NULL,
    datamodel text NOT NULL,
    status text NOT NULL,
    applied integer NOT NULL,
    rolled_back integer NOT NULL,
    datamodel_steps text NOT NULL,
    database_migration text NOT NULL,
    errors text NOT NULL,
    started_at timestamp(3) without time zone NOT NULL,
    finished_at timestamp(3) without time zone
);

CREATE SEQUENCE public."_Migration_revision_seq"
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER TABLE ONLY public."_Migration" ALTER COLUMN revision SET DEFAULT nextval('public."_Migration_revision_seq"'::regclass);
ALTER TABLE ONLY public."_Migration"
    ADD CONSTRAINT "_Migration_pkey" PRIMARY KEY (revision);

@radicand I was given a workaround of deleting my migrations in /prisma/migrations (including the .lock file) and the _Migrations table in the DB.

Very low impact for me since I've no data that needs preserving at the moment and my migrations were a mess from experiments.

For those that find this with the same/similar issue: Resetting migrations worked for me but please keep in mind that YMMV.

@its-kyle-yo thanks, I did see that note in Slack. I have data in my "faux-production" database, I'd rather sit out p025 if the error will resolve in a subsequent release. If this is a wont-fix, than I'll go the route you suggest and dump/reimport after.

@radicand It was breakage in the migration file format that we did not spot, so it's not in the release notes (we do not have comprehensive tests for backwards compatibility yet, as migrate is still experimental, but we absolutely will - moreover there is a lot of churn in introspection and the schema at the moment, and this is what made it break). Deleting your migrations folder and re-migrating should fix this without losing your data, but please make a backup before if it is important. Sorry for the breakage, we try to keep it to a minimum but it will definitely happen again while migrate is behind the --experimental flag.

Thanks, I've confirmed the following does not affect existing data in the database:

  • Delete prisma/migrations/ folder
  • Drop _Migration table
  • Create/Save a new initial migration
  • Run migrate up

This can probably be closed as wontfix as it's a relatively easy thing to work around during the preview phase.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

2013-11390 picture 2013-11390  ยท  3Comments

MichalLytek picture MichalLytek  ยท  3Comments

chanphiromsok picture chanphiromsok  ยท  3Comments

divyenduz picture divyenduz  ยท  3Comments

jwld picture jwld  ยท  3Comments