error creating relationship
I'm having trouble creating a relationship in MySQL using drizzle-orm, I'm running
npx drizzle-kit push:mysql
but the I'm trying running the code inside my MySQL database but I'm getting this error
Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'anime_user_id_users_id_fk' are incompatible.
here is the schema and the generated SQL migration code.
2 Replies
Case here is that MySQL needs to have exact same types for columns, that are referencing each other
id
is a serial
, which is an alias for bigint unsigned not null auto_increment unique
So it means, that user_id
should also be of type bigint unsigned
Another case is that drizzle-orm doesn't have support for unsigned types(yet). So you way is to not use serial in users.id
you can use those schemas
this should work fine for youThank you very much for the help.