Hello! I added a relation to the schema and it loo...
# orm-help
c
Hello! I added a relation to the schema and it looks like
Copy code
model Company {
  id        Int   @id
  name     String
  users User[]
}

model User {
  userId        Int       @default(autoincrement()) @id
  companyId     Int?
  worksAt   Company? @relation(fields: [companyId], references: [id])
  email         String?   @unique
  name          String
  password      String
  @@map(name: "users")
When I run $ prisma db push I get this error. Any assistance will be appreciated
r
@Charity Darko 👋 Did you already have relation data or the
companyId
field in the database before running
db push
?
c
Yes @Ryan Schema Before
Copy code
model Company {
  companyId        Int     @default(autoincrement()) @id
  name     String
}

model User {
  userId        Int       @default(autoincrement()) @id
  companyId     Int
  email         String?   @unique
  name          String
  password      String
  @@map(name: "users")
}
Schema After
Copy code
model Company {
  id        Int   @id
  name     String
  users User[]
}

model User {
  userId        Int       @default(autoincrement()) @id
  companyId     Int?
  worksAt   Company? @relation(fields: [companyId], references: [id])
  email         String?   @unique
  name          String
  password      String
  @@map(name: "users")
}
r
In that case, you can make this work with any one of the below options: 1. Deleting all data in the 
companyId
 field and then running 
db push
2. Manually checking what 
companyId
 rows do not match an existing 
Company
  and deleting/fixing these.
👍 1
c
The first option worked perfectly. Thanks @Ryan 👍