没有主键就无法创建或更改表-Laravel DigitalOcean托管数据库 [英] Unable to create or change a table without a primary key - Laravel DigitalOcean Managed Database
问题描述
我刚刚使用(托管数据库)将我的应用程序部署到DigitalOcean,并且在调用 php artisan migration
I've just deployed my app to DigitalOcean using (Managed Database) and I'm getting the following error when calling php artisan migrate
SQLSTATE [HY000]:常规错误:3750当设置了系统变量'sql_require_primary_key'时,无法创建或更改没有主键的表.将主键添加到表中或取消设置此变量以避免出现此消息.请注意,没有主键的表可能会导致基于行的复制中的性能问题,因此在更改此设置之前,请咨询您的DBA.(SQL:创建表`sessions`(`id` varchar(255)不为null,`user_id` bigint无符号为null,`ip_address` varchar(45)为null,`user_agent`文本为null,`payload`文本不为null,`last_activity`int not null)默认字符集utf8mb4整理'utf8mb4_unicode_ci')
当mysql var sql_require_primary_key
设置为true时,Laravel迁移似乎不起作用.
It appears that Laravel Migrations doesn't work when mysql var sql_require_primary_key
is set to true.
您对此有任何解决方案吗?
Do you have any solutions for that?
推荐答案
此系统变量的MySQL文档目的是
According to the MySQL documentation purpose of this system variable is
避免复制性能问题:启用此变量有助于避免表没有主键时可能发生的基于行的复制中的性能问题."
to avoid replication performance issues: "Enabling this variable helps avoid performance problems in row-based replication that can occur when tables have no primary key."
恕我直言,有两种可能的解决方案可供您考虑;
IMHO, there are two possible options to consider for your problem;
- 向迁移表以及迁移中的每个表(包括临时表)添加主键.这个更好,我认为这样做更方便,因为每个表都没有主键是没有缺点的.
创建新表或更改现有表结构的语句是否强制要求表具有
我们仅支持MySQL v8."
- 根据此处的说明更改提供商,
这也是错误报告
这篇关于没有主键就无法创建或更改表-Laravel DigitalOcean托管数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!