Sync2同步mysql数据库错:needed in a foreign key constraint #1628

Closed
opened 2020-03-25 12:09:35 +00:00 by jiangrzh · 0 comments

建立了两个model:

// Realm ...
type Realm struct {
	NodeId int    `xorm:"NODE_ID" msgpack:"NodeId"`
	Policy string `xorm:"POLICY" msgpack:"Policy"`
}

// Domain ...
type Domain struct {
	Name    string `xorm:"NAME" msgpack:"Name"`
	RealmId int    `xorm:"REALM_ID" msgpack:"RealmId"`
	Realm   `xorm:"extends" msgpack:"Realm"`
}

在程序初始化的时候执行了Sync2, 结果程序报错

Error 1553: Cannot drop index 't_domain_t_realm_ID_fk': needed in a foreign key constraint

执行的SQL为:

DROP INDEX t_domain_t_realm_ID_fk ON t_domain

这里是不是应该先使用:

ALTER TABLE t_domain DROP FOREIGN KEY
把外键给disable先?

建立了两个model: ``` Go // Realm ... type Realm struct { NodeId int `xorm:"NODE_ID" msgpack:"NodeId"` Policy string `xorm:"POLICY" msgpack:"Policy"` } // Domain ... type Domain struct { Name string `xorm:"NAME" msgpack:"Name"` RealmId int `xorm:"REALM_ID" msgpack:"RealmId"` Realm `xorm:"extends" msgpack:"Realm"` } ``` 在程序初始化的时候执行了Sync2, 结果程序报错 > Error 1553: Cannot drop index 't_domain_t_realm_ID_fk': needed in a foreign key constraint 执行的SQL为: > DROP INDEX `t_domain_t_realm_ID_fk` ON `t_domain` 这里是不是应该先使用: > ALTER TABLE t_domain DROP FOREIGN KEY 把外键给disable先?
lunny added the
duplicate
label 2020-03-25 12:41:17 +00:00
lunny closed this issue 2020-03-25 12:41:31 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1628
No description provided.