I’m trying to migrate a TypeORM project to primsa....
# orm-help
c
I’m trying to migrate a TypeORM project to primsa. I’ve pulled the data, and the schema is created Modified with @@map to reflect the names When I try to run
npx prisma migrate dev
I get the following:
Copy code
[*] Changed the `photo` table
  [+] Added foreign key on columns (userId)

? We need to reset the PostgreSQL database "test_db" at "localhost:5432".
Do you want to continue? All data will be lost.
How can I go about keeping my data whilst migrating to Prisma from TypeORM? The TypeORM looks like this:
Copy code
@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @OneToMany((type) => Photo, (photo) => photo.user)
  photos: Photo[];
}

@Entity()
export class Photo {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne((type) => User, (user) => user.photos)
  user: User;
}
s
Hey Chris! Could you share your prisma schema? Also did you use
introspect
to pull the existing database's schema down first, or build it manually?
c
Hey @Sabin Adams I used
npx prisma db pull
Then I added the @@map function The full schema:
Copy code
generator client {
  provider = "prisma-client-js"
}

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

model Photo {
  id          Int     @id(map: "PK_723fa50bf70dcfd06fb5a44d4ff") @default(autoincrement())
  name        String  @db.VarChar(100)
  description String
  filename    String  @db.VarChar
  views       Int
  isPublished Boolean
  userId      Int?
  user        User?   @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "FK_4494006ff358f754d07df5ccc87")

  @@map('photo')
}

model User {
  id        Int     @id(map: "PK_cace4a159ff9f2512dd42373760") @default(autoincrement())
  firstName String  @db.VarChar
  lastName  String  @db.VarChar
  age       Int
  photo     Photo[]

  @@map('user')
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model typeorm_metadata {
  type     String  @db.VarChar
  database String? @db.VarChar
  schema   String? @db.VarChar
  table    String? @db.VarChar
  name     String? @db.VarChar
  value    String?

  @@ignore
}
s
I'll try to recreate tonight to see if I can find a way around the problem (or recreate the problem at least). I'll let you know what I find!
2