after reverse Engineer MySQL Workbench change 1:1 relationship to 1:n

余生颓废 提交于 2021-02-07 10:15:44

问题


I am working with MYSQL WORKBENCH. After forward engineer I got all my tables in phpadmin.

But the reverse enginner transforms 1:1 to 1:n .

How can I fix this?


回答1:


I believe it's a limitation of the forward and reverse engineering processes in MySQL Workbench. The cardinality of the relationship should determine the type of index used for the generated foreign key. Hence a unique index (or a primary key, which is per definition unique) are needed for a cardinality of 1. A non-unique index allows the 1..n cardinality. You cannot model the 0..1 cardinality with foreign keys, however, as foreign keys always require at least one entry (that's their entire purpose, after all).

If you like you can create a bug report (http://bugs.mysql.com) to have this improved.




回答2:


Yes,I faced this problem when using django to model 1:1 relationship like this:

class Server(models.Model):
    ...
    asset = models.OneToOneField('Asset', on_delete=models.CASCADE, null=True, blank=True)

after python makemigrations & python migrate, I run mysql workbench(6.3 on ubuntu16.04) reverse engineer,than something show as follow: 1_to_1_bug.png



来源:https://stackoverflow.com/questions/33417257/after-reverse-engineer-mysql-workbench-change-11-relationship-to-1n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!