简体   繁体   English

错误1075:表定义不正确; 只能有一个自动列,它必须被定义为一个键(使用 gorm 和 mysql)

[英]Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key (using gorm and mysql)

when I add gorm model to my struct i got this error当我将 gorm 模型添加到我的结构时,出现了这个错误

im using gorm model in my other 3 struct but only when i add this to my journal struct i got error Error 1075: Incorrect table definition;我在我的其他 3 个结构中使用 gorm 模型,但只有当我将其添加到我的日志结构时,我才收到错误错误 1075:不正确的表定义; there can be only one auto column and it must be defined as a key here are my structs只能有一个自动列,它必须被定义为一个键这里是我的结构

package migrations

import "gorm.io/gorm"

type Category struct {
   gorm.Model
   Title string `gorm:"type:varchar(255)"`
   Sort  int    `gorm:"sort"`
}

package migrations包迁移

import "gorm.io/gorm"导入“gorm.io/gorm”

type Contents struct { gorm.Model CategoryId uint CategoryModel Category gorm:"foreignKey:category_id" Title string gorm:"type:varchar(255)" Content string gorm:"content" Status bool gorm:"default:true" Sort int gorm:"sort" Images []Image gorm:"foreignKey:content_id" } type Contents struct { gorm.Model CategoryId uint CategoryModel Category gorm:"foreignKey:category_id"标题字符串gorm:"type:varchar(255)"内容字符串gorm:"content" Status bool gorm:"default:true"排序 int gorm:"sort"图像 []Image gorm:"foreignKey:content_id" }

package migrations

import "gorm.io/gorm"

type Image struct {
   gorm.Model
   ContentId    uint
   ContentModel Contents `gorm:"foreignKey:content_id"`
   Title        string   `gorm:"type:varchar(255)"`
   File         string
   Sort         int `gorm:"sort"`
}

//`gorm:"type:varchar(255)"`
package migrations

import "gorm.io/gorm"

type Journal struct {
   gorm.Model
   ModelName string `gorm:"ModelName"`
   UpdatedBy string `gorm:"UpdatedBy"`
   Row       uint   `gorm:"foreignKey:category_id"`
   NewValue  string `gorm:"newValue"`
   OldValue  string `gorm:"oldValue"`
   Column    string `gorm:"Column"`
}



When gorm do migration it usually migrates what is added to table.当 gorm 进行迁移时,它通常会迁移添加到表中的内容。 But if you remove any thing from struct that thing is not removed from table while migration.但是,如果您从结构中删除任何东西,那么在迁移时该东西不会从表中删除。 Suppose there was a Key column of auto type.假设有一个auto类型的Key列。 If you remove it from struct it will not be auto removed from table after migration rather you need to manually remove it from table.如果您将其从结构中删除,迁移后它不会自动从表中删除,您需要手动将其从表中删除。 I think this type of scenario happened with you.我认为这种情况发生在你身上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL-1075错误的表格定义,只能有一个自动列,必须将其定义为键 - MySQL - 1075 Incorrect table definition, there can be only one auto column and it must be defined as a key 错误1075:错误的表格定义; 只能有一个自动列,并且必须将其定义为键 - ERROR 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key ERROR 1075 表定义不正确; 只能有一个自动列,并且必须将其定义为键 - ERROR 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key Phpmyadmin#1075-错误的表定义; 只能有一个自动列,并且必须将其定义为键 - Phpmyadmin #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key #1075-错误的表格定义; 只能有一个自动列,并且必须将其定义为键 - #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key 导入WordPress数据库 - #1075 - 表定义不正确;只能有一个自动列,必须将其定义为键 - Importing WordPress Database - #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key "<i>#1075 - Incorrect table definition;<\/i> #1075 - 表定义不正确;<\/b> <i>there can be only one auto column and it must be defined as a key<\/i>只能有一个自动列,并且必须将其定义为键<\/b>" - #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key SQLSTATE[42000]:语法错误或访问冲突:1075 不正确的表定义; 只能有一个自动列,并且必须将其定义为键 - SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key Data Nucleus-MySql错误的表定义; 只能有一个自动列,并且必须将其定义为关键错误 - Data Nucleus-MySql Incorrect table definition; there can be only one auto column and it must be defined as a key error MySQL错误:错误的表格定义; 只能有一个自动列,并且必须将其定义为键 - MySQL error: Incorrect table definition; there can be only one auto column and it must be defined as a key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM