Hello,
I thought the id field for a custom table in ExtraBuilder is created automatically?
The table created without id auto_increment field.
So, I added an field id, but how could I tell ExtraBuilder to create an auto_increment?
Schema Version: 3.0
Thanks for help and clarification.
Bye
Chris
If you extend xPDO\Om\xPDOSimpleObject
for your class/table, then it creates an âidâ column for you automatically.
If you extend xPDO\Om\xPDOObject
however, you have to add the âidâ column yourself.
oh, thank you.
and how could I create attribute âauto_incrementâ?
With an index. The schema would look something like this:
<object class="MyClass" table="myprefix_myclass" extends="xPDO\Om\xPDOObject">
<field key="id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
...
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
<column key="id" length="" collation="A" null="false" />
</index>
</object>
great.
I placed:
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
<column key="id" length="" collation="A" null="false" />
</index>
under âRaw XML (Define additional rules or schema values for edge cases)â
but the id field created, is not auto_increment.
What do I have made wrong?
I think I made a mistake. It seems you have to add index="pk" generated="native"
to the field to make it work:
how could I add this in Manage fields in ExtraBuilder?
Till now I havenât managed to create an id field in ExtraBuilder that is auto_increment
Iâm not that familiar with ExtraBuilder .
Canât you just change the âExtends Object (Default xPDOSimpleObject)*:â property of the âObjectâ to xPDO\Om\xPDOSimpleObject
, so it creates the primary key automatically?
To manually create a primary key, maybe try the field âAdditional Attributesâ or âGeneratedâ (= native
).
If I change it to xPDOSimpleObject
is it still schema 3.0 for modx3?
Probably not.
You can preview the schema in ExtraBuilder (âSchema Actionsâ â âPreview Schemaâ).
It should look like this:
<object ... extends="xPDO\Om\xPDOSimpleObject">
halftrainedharry:
xPDOSimpleObject
with this changes, now it runs.
the builder creates the id field with auto_increment.
Many thanks
1 Like