Schema Troubleshooting
Hi everyone reposting this, i have a pretty simple Schema with three models. However, whenever i try to push the schema to my MYSQL DB, i keep running into foreign key restraints. I don't see anything wrong with my relations thats causing this to occur. One thing to note is that i did accidentally migrate the schema to my db, but i went and dropped the table and the migration folder. Did I make a silly syntax mistake that i'm missing, or will i need to baseline my db due to migrations being out of sync?


2 Replies
Salutations, traveler! I'm the Prisma AI Help Bot. You've reached a fork in the road: one path leads to the wisdom of the human sages (ETA: sometime today), and the other to my instantaneous insights. Which way shall we go?
generator client {
provider = "prisma-client-js"
previewFeatures = ["metrics"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model User {
userID Int @id @default(autoincrement()) //primary key of the user table
username String @unique
password String
email String @unique
emailVerified Boolean @default(false)
listings Listing[] //one to many relationship. One user can have many listing
allBids Bid[] // one to many relationship. One user can have many bids
}
model Listing {
listingID Int @id @default(autoincrement()) //primary key of the Listing table
sellerID Int //foreign key of the user table is stored here. This is the user who is creating the listing
listCreationTimestamp DateTime @default(now())
listExpirationTimestamp DateTime @default(dbgenerated("DATE_ADD(NOW(), INTERVAL 2 DAY)")) //when the auction is over
closedListing String @default("open")
listTitle String
listDesc String?
listImg Bytes? @db.LongBlob
currentBid Int @default(0) //remove from schema to futher normalize, we can use this value by joining the bid table
creator User @relation(fields: [sellerID], references: [userID])
highBider Bid? //one to one relation.
}
model Bid {
bidID Int @id @default(autoincrement()) //primary key of the table of the Bid table
listID Int @unique //foreign key of the listing table. represents the listing that users are bidding on.
bidderID Int //foreign key of the user table. represents the user who is bidding on a listing
value Int @default(0) //must be greater than 0
bidder User @relation(fields: [bidderID], references: [userID]) //establishing the foreign key of the user table.
bidOnListing Listing @relation(fields: [listID], references: [listingID]) //establishing the foreign key of the Listing table.
}