gorm 建立many2many關系的坑


使用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;"`

問題就解決了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM