Prisma migrate returns error for a field that was already removed
Hi, i'm using prisma with cokroachDB and I made a few changes to my schema and tried to migrate, but prisma returns an error that mentions a field that doesn't exist (it did exist in former migration).
It seems to not realize that I've changed the schema.
Can I delete all past migrations? maybe it'll help
25 Replies
you can try to pull the schema
and see what happens
it brought back an old version with that field
yep
so the field wasnt removed after all
yea but like what can I do? up until now I always migrated and it updated correctly
you can remove the field from the schema
migrate
and check the db
npx prisma studio
if the field still there
you should open an issue on githubWhen I load the studio, it says that the updated column: "does not exist in the current database.".
I did remove the old one from the schema and tried to migrate, but like i've said, the migrate fails, it returns an errur that metionts the old column
can you show the error?
the column that doesn't exist anymore is magicIds
the error is on the migration itself for some reason
[]string !== string
do you have the prisma vscode extension?
yes
its just really weird
prisma didnt get the correct migration
in my case I can clean the entire DB and mgirations if that will do any good
you can try
but the issue is the type itself
the error is
yea i've since then changed the type
[]string !== string
yea now I have
Magic Magic[]
on my character schema
and:
character Character? @relation(fields: [characterId], references: [id])
characterId String
on my magic schema
that's what i'm trying to update
many to many?
maybe that's my mistake, like I wasn't sure if its many to many or not, in my case a character can have many magic, and magic can be used by many characters, is that many to many?
yes
many chars can have multiple magics
many magics can belong to multiple chars
TomDoesTech
YouTube
Learn Prisma Relationships (1-1, 1-m, m-m)
Prisma makes managing complicated relationships simple. By watching this video you will learn how to model and work with the most common relationships you will be creating in your applications.
0:00 Intro
1:28 One-to-one
9:09 One-to-many
16:01 Many-to-many
21:05 Many-to-many self reference
Repository: https://github.com/TomDoesTech/prisma-rela...
Thanks a lot, will check that out! haven't done any backend thinking in a while 😅
Wow the migrations of the guy in the video are super fast, is this edited or just mine are slow? XD
maybe the db
in my experience
mysql migrations are slow compared to pg
Hey your suggestion was great, I just have 1 more question.
When I create a character, I want to also give it multiple existing magic.
Ive seen the examples with:
connect: {
id: something,
},
but it only adds one, based on the id I gave.
How can I add an array of Ids?
i think you can just add a [something1, something2]
That's weird, I did:
magic: {
connect: {
id: [...magic],
},
},
But got an error that it expects a string and got a list of strings.
This is how magic is configured on the schema:
magic Magic[]