• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Still_Walking

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

gorm 建立many2many关系的坑

Incorrect table definition; there can be only one auto column and it must be defined as a key

使用gorm建立多对多关系时,发现没有成功,报错:Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key

查看代码发现在,我的两个主表的ID都写了type:int(11) unsigned auto_increment;

我使用的是mysql,不能有多个自增长的列。

 

参考gorm.Model的写法,于是把ID改`gorm:"primary_key;comment:记录ID;"`

问题就解决了。

 

posted on 2021-08-19 17:27  limanxian  阅读(734)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3