Hello everyone I have been losing my mind on a pr...
# orm-help
c
Hello everyone I have been losing my mind on a problem recently I have two models such as:
Copy code
model Event {
  evt_id           String        @id @default(uuid())
  evt_title        String        @db.VarChar(100)
  evt_content      String        @db.VarChar(1024) @default("Cet événement n'a pas encore de description.")
  evt_picture      String?       @db.VarChar(1024) @default("/img/events/default.png") // Local path
  evt_likeCount    Int           @default(0)
  evt_beginDate    DateTime
  evt_endDate      DateTime
  evt_participants User[]
  evt_created_at   DateTime      @db.Timestamp() @default(now())
  evt_updated_at   DateTime      @updatedAt
  evt_isVerified   Boolean
}

model User {
  usr_id                     String            @id @default(cuid())
  usr_token                  String            @db.VarChar(1024) @unique
  usr_name                   String?           @db.VarChar(100)
  usr_nickname               String?           @db.VarChar(32) @unique
  usr_email                  String            @db.VarChar(100) @unique
  usr_profilePicture         String?           @db.VarChar(1024) @default("/img/users/default.png") // Local path
  usr_events                 Event[]
  usr_createdAt              DateTime          @db.Timestamp @default(now())
}
I created my database etc using npx prisma generate, and I have no migration in this project But when accessing the studio, I get the error: ``The table
public._EventToUser
does not exist in the current database.`` Oh boy I don't understand from where this could even come from... Could someone indicate me the path? I feel like this is an internal thing for prisma, but cannot find anything......
r
Hi @Clément Guibout 👋 You will need to either generate a migration with the command
npx prisma migrate dev --name init
or you use the
npx prisma db push
command in order to have Prisma synchronize your Prisma Schema with your database schema. After either of these previous commands finishes, you can then run
npx prisma generate
. You can follow this guide to help you understand the workflow better.
👀 1
c
Hello Raphael Thanks again for the quick response The this that I don't understand is that when starting my backend, I already run npx prisma generate && npx prisma migrate deploy. Shouldn't this already do the job?
Also, after running both of the told commands in my docker and restarting the service, I still get the same error in the prisma cloud studio.
Copy code
Message: Error in Prisma Client request: 


Invalid `prisma.event.findMany()` invocation:


The table `public._EventToUser` does not exist in the current database.
Does someone else have any idea? I've been trying things and things since without being able to solve it..
a
Hey @Clément Guibout, What database are you using?
c
Hello I am using postgresql
a
I was not able to recreate this using Postgres and Prisma 4.3.1. After running
npx prisma migrate --create-only
, the generated migration file had a statement to create the
_EventToUser
table and after running
npx prisma migrate deploy
I could open Prisma Studio without issue. Are you using the latest Prisma version?
c
I guess so, the version is 4.3.1
a
Have you ran either
npx prisma db push
or
npx prisma migrate dev
?
c
migrate dev I don't think so, but db push and migrate deploy yes I did
Does migrate dev has a massive difference with deploy?
a
prisma migrate dev
actually generates a migration file and applies it to the current database.
prisma migrate deploy
does not generate migration files, it only applies those that are found in the migrations folder.
prisma db push
syncs your schema file directly to the database, without generating migration files. Database resets are likely in when using this command. Have you double-checked your database to see if the
_EventToUser
table actually exists?
c
Actually I cannot do that
When I had the problem, I had a one-to-one relationship between my two tables, and I was having this issue Since then, I had to update my model to a many-to-many relationship (just two in both directions), and I no longer have any issue I am now just trying to understand what was happening
But I am pretty sure that _EventToUser was missing honestly :')
But I remember for sure doing db push, since it still is in my starting script
a
If you can reproduce the same issue again, feel free to open a GitHub Discussion 👍. Best of luck!
c
I will, thank you sir