Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disable `sql_require_primary_key` per database?

I have a Digital Ocean-managed MySQL database. In order to prevent data replication issues across nodes, DO automatically sets your instance with sql_require_primary_key. This is fine in theory except that there are various WordPress plugins, including notably WP Cerber, which do not support that setting.

I can ask Digital Ocean to disable the setting for me, but I run the risk of my data not replicating properly. So what I'm wondering is, is there a way to disable that setting for specific databases and even tables, or is that setting restricted to the connection settings and the server-wide settings?

like image 394
selfagency Avatar asked May 28 '26 11:05

selfagency


1 Answers

You can temporarily disable it at the session level.

SET SESSION sql_require_primary_key = 0;

I have some migration code that makes primary keys after it makes the table. I added the above snippet to the migration before the table is created. In the end it does make a primary key so all is well.

like image 103
ryantxr Avatar answered May 31 '26 06:05

ryantxr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!