Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primary key + Composite primary key causing issue in propel database schema

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 use findPK(). I would prefer to have an auto-incremented id as primary key but I also want to make sure that the combo field1 + 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" />
like image 848
twitter Avatar asked Mar 06 '26 05:03

twitter


1 Answers

Try setting an unique index on those fields, something like :

<unique>
  <unique-column name="/field1/" />
  <unique-column name="/field2/" />
</unique>

as per propel doc

like image 75
yent Avatar answered Mar 07 '26 17:03

yent