Skip to content
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

Handle error ERROR 70100 (1317): foreign key constraints are not allowed, see https://code.openark.org/blog/mysql/the-problem-with-mysql-foreign-key-constraints-in-online-schema-changes #7384

Closed
janpio opened this issue May 31, 2021 · 1 comment · Fixed by prisma/prisma-engines#2068

Comments

@janpio
Copy link
Member

janpio commented May 31, 2021

PlanetScale or Vitess (with foreign_key_mode=disallow) throws the following error if you try to create a foreign key:

Error: Database error
Error querying the database: Server error: `ERROR 70100 (1317): foreign key constraints are not allowed, see https://code.openark.org/blog/mysql/the-problem-with-mysql-foreign-key-constraints-in-online-schema-changes'
   0: sql_migration_connector::sql_database_step_applier::apply_migration
             at migration-engine\connectors\sql-migration-connector\src\sql_database_step_applier.rs:15
   1: migration_core::api::SchemaPush
             at migration-engine\core\src\api.rs:163

To reproduce: Run a DDL statement that creates a foreign key on a non production branch (created via UI) on a PlanetScale database.

We should catch this and output a known error message with the following message text:

Foreign keys can not be created on this database. Learn more how to handle this: https://pris.ly/d/migrate-no-foreign-keys

(The link currently points to a rather general issue, but will be updated to point to a specific issue or documentation later)

The Vitess instances we are testing against do not show this behavior by default yet, but can be configured to do so via FOREIGN_KEY_MODE: disallow in docker-compose.yml. (Outstanding PR at prisma/prisma-engines#1958)

@janpio
Copy link
Member Author

janpio commented Jul 9, 2021

I think this works:

C:\Users\Jan\Documents\throwaway\pscaleMigrationTable>npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "migration-table-3" at "127.0.0.1:56287"

Error: P3006

Migration `20210709232641_bar` failed to apply cleanly to the shadow database. 
Error code: P3018
Error:
A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 20210709232641_bar

Database error code: 1317

Database error:
Foreign keys cannot be created on this database. Learn more how to handle this: https://pris.ly/d/migrate-no-foreign-keys

Please check the query number 2 from the migration file.

A direct reference to the migration sql file would be nice here, but that is unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants