Skip to content

Instantly share code, notes, and snippets.

@chris-cmsoft
Created October 28, 2021 07:45
Show Gist options
  • Save chris-cmsoft/73fe7c284c927c016458aa2801508fc5 to your computer and use it in GitHub Desktop.
Save chris-cmsoft/73fe7c284c927c016458aa2801508fc5 to your computer and use it in GitHub Desktop.
Laravel - Switch off sql_require_primary_key for DigitalOcean managed database
# app/Providers/AppServiceProvider.php
public function register()
{
// https://github.com/laravel/framework/issues/33238#issuecomment-897063577
Event::listen(MigrationsStarted::class, function () {
DB::statement('SET SESSION sql_require_primary_key=0');
});
Event::listen(MigrationsEnded::class, function () {
DB::statement('SET SESSION sql_require_primary_key=1');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment