-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Standardized way to disable foreign key constraints #2502
Comments
We would need to implement this at the Schema builder layer. Even then I'm not sure we can do it easily across all platforms. |
Some info I have found (mostly unverified/untested) for each of the PDO drivers. -- Disable checks:
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";
-- Enable checks:
EXEC sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all";
-- Disable checks:
SET FOREIGN_KEY_CHECKS = 0;
-- Enable checks:
SET FOREIGN_KEY_CHECKS = 1;
-- Disable checks:
PRAGMA foreign_keys = OFF;
-- Enable checks:
PRAGMA foreign_keys = ON;
-- Disable checks:
ALTER DATABASE DISABLE CONSTRAINTS;
-- Enable checks:
ALTER DATABASE ENABLE CONSTRAINTS;
|
Wouldn't it be possible to implement this at the DB facade level?
And have it work on each separate DB engine in it's own engine-specific way, if any. If no specific way to do it, then simply do nothing? |
+1 |
When I tried |
@anik786 No, it isn't implemented yet, as proven by a simple "Find in all files" search within the repository. The alternative is to use the code posted by the original poster/reporter depending on your sql server. In my case, I use MySQL, so I use the following: |
1+ for @ikari7789 |
Currently experiencing this issue in 5.1 so i have a little workaround inusing for the time being on till Taylor have time to integrate it inside the framework.
|
I am having an issue with disabling foreign key checks differently in my different environments. I am trying to use SQLite for testing and MySQL for development/production. Each has their own way to disable foreign key checks.
MySQL:
SQLite:
The text was updated successfully, but these errors were encountered: