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

Open
opened 2020-03-25 12:09:34 +00:00 by jiangrzh · 2 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
kind
enhancement
label 2020-03-25 12:42:42 +00:00
Owner

Currently we haven't support foreign key.

Currently we haven't support foreign key.

@lunny Glad you guys took right decision.

@lunny A bit of request when you consider implementing this feature, can you also keep in mind about NoSQL databases. which doesn't support FK and when using this ORM moving from databases especially switching from SQL to NoSQL will be a problem

@lunny Glad you guys took right decision. @lunny A bit of request when you consider implementing this feature, can you also keep in mind about NoSQL databases. which doesn't support FK and when using this ORM moving from databases especially switching from SQL to NoSQL will be a problem
Sign in to join this conversation.
No Milestone
No Assignees
3 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#1627
No description provided.