无法创建或更改没有主键的表 - Laravel DigitalOcean 托管数据库 [英] Unable to create or change a table without a primary key - Laravel DigitalOcean Managed Database

查看:169
本文介绍了无法创建或更改没有主键的表 - Laravel DigitalOcean 托管数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用(托管数据库)将我的应用程序部署到 DigitalOcean,调用 php artisan migrate

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: create table `sessions` (`id` varchar(255) not null, `user_id` bigint unsigned null, `ip_address` varchar(45) null, `user_agent` text null, `payload` text not null, `last_activity` int not null) 默认字符集 utf8mb4 collat​​e '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.

你有什么解决办法吗?

推荐答案

根据 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;

  • 向此表和迁移中的每个表(包括临时表)添加主键.这个更好,我认为这样做更方便,因为每个表都有主键没有缺点.

创建新表或更改现有表结构的语句是否强制要求表具有 主键.

Whether statements that create new tables or alter the structure of existing tables enforce the requirement that tables have a primary key.

  • 更改您的提供商,因为根据 此处我们仅支持 MySQL v8."
    • Change your provider because according to here "We support only MySQL v8."
    • 这里还有 错误报告

      这篇关于无法创建或更改没有主键的表 - Laravel DigitalOcean 托管数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆