-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Not Authorised" when directly applying Prisma generated migrations to Cloudflare D1 with PRAGMA foreign_key_check;
#23827
Comments
PRAGMA foreign_key_check;
Considering this may be related to wrangler cli from Cloudflare not giving us the necessary permissions, have added an issue there: cloudflare/workers-sdk#5598 |
Currently, the workaround is to remove this from the generated migration SQL file. That should allow you to apply the migration successfully and will most probably not cause any problems. We are currently investigating how we can avoid this problem. |
Hi, this should be fixed now in a dev (unstable) version of Prisma: For production usage, we recommend waiting for the next stable version, Prisma I will close the issue for now, but you're still welcome to add comments below. |
Thank you 🙏🏼 |
Bug description
When we change a column in a table with foreign keys, Prisma CLI generates the migrations properly when we run
migrate diff
but a particular line is inserted in the sql statements that are output:PRAGMA foreign_key_check;
When you try to apply these migrations to either Cloudflare D1 local or remote databases, it fails with the error "not authorized". The above line is where this error is happening. The rest of the sql statements generated work perfectly.
How to reproduce
Create a simple prisma schema with 2 tables dependent on each other (maybe User and Session tables)
Generate migrations and apply to local and remote databases of Cloudflare D1
You can use this link for detailed instructions on how to do that: https://www.prisma.io/docs/orm/overview/databases/cloudflare-d1
Change something in the session table like a column name from userId to user_id
And regenerate migrations. Again, details on how here: https://www.prisma.io/docs/orm/overview/databases/cloudflare-d1#3-generate-sql-statements-using-prisma-migrate-diff-1
View the generated migrations sql file. If you try and apply the migrations, you will get the error.
It looks like this in the console:
Expected behavior
It should ideally allow us to run
PRAGMA foreign_key_check;
Current workaround, apply migrations line by line manually or remove the line causing issues.
Prisma information
Initial Prisma Schema:
Modified Prisma Schema:
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: