Primary key + Component primary key causing a problem in the propel database schema

I have a table that uses a primary key with automatic addition and 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 the field1+ combination is field2not used more than once, so I added them as primary keys in addition to the identifier, but this creates problems when I try to use findPK(). I would prefer that auto-incremented id be added as the primary key, but I also want to make sure that combo field1+ is field2not 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" />
+3
source share
2 answers

Try setting a unique index in these fields, for example:

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

propel doc

+4

yaml

Pet:
  columns:
    pet_name:  {type: string(32)}
    owner_id: {type: integer}
  indexes:
    owner_name:
      fields: [pet_name, owner_id]
      type: unique
0

Source: https://habr.com/ru/post/1794745/


All Articles