主键+复合主键导致在推进数据库模式中出现问题 [英] Primary key + Composite primary key causing issue in propel database schema
本文介绍了主键+复合主键导致在推进数据库模式中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表使用自动递增的主键,它有几个字段。
< column name =idtype =INTEGERprimaryKey =truerequired =trueautoIncrement =真/>
< column name =field1type =INTEGERrequired =true/>
< column name =field2type =INTEGERrequired =true/>
< column name =field3type =INTEGER/>
< column name =field4type =INTEGER/>
< column name =field5type =INTEGER/>
我想确保 field1
+ field2
combo不被使用多次,所以我添加它们作为主键除了id,但这是创建问题,当我尝试使用 findPK()
。我希望有一个自动递增的id作为主键,但我也想确保组合 field1
+ field2
不多次输入。
< column name =idtype =INTEGERprimaryKey =truerequired =trueautoIncrement =真/>
< column name =field1type =INTEGERneed =trueprimaryKey =true/>
< column name =field2type =INTEGERrequired =trueprimaryKey =true/>
解决方案
尝试在这些字段上设置唯一索引, :
< unique>
< unique-column name =/ field1 //>
< unique-column name =/ field2 //>
< / unique>
I have a table that uses an auto-incremented primary key and it has several fields.
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" /> <column name="field1" type="INTEGER" required="true" /> <column name="field2" type="INTEGER" required="true" /> <column name="field3" type="INTEGER" /> <column name="field4" type="INTEGER" /> <column name="field5" type="INTEGER" />
I want to make sure that a
field1
+field2
combo isn't used more than once, so I added them as primary keys in addition to the id, but this is creating problems when I try to usefindPK()
. I would prefer to have an auto-incremented id as primary key but I also want to make sure that the combofield1
+field2
isn't entered more than once.<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" /> <column name="field1" type="INTEGER" required="true" primaryKey="true" /> <column name="field2" type="INTEGER" required="true" primaryKey="true" />
解决方案Try setting an unique index on those fields, something like :
<unique> <unique-column name="/field1/" /> <unique-column name="/field2/" /> </unique>
as per propel doc
这篇关于主键+复合主键导致在推进数据库模式中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文