1

I am doing a project which is using MDB2 implementation.

I wanna to set a foreign key on xml schema file. There are only 3 tables: student, course, and enrollment where enrollment is serve as a bridge entity.

Here is my xml file for enrollment.

<database>
<name>mdb2_schema_demo</name>
<charset>utf8</charset>
<description>A database to demo MDB2 schema sync</description>

<table>
    <name>enrollment</name>
    <declaration>
        <field>
            <name>id</name>
            <type>integer</type>
            <notnull>1</notnull>
            <autoincrement>1</autoincrement>
            <unsigned>1</unsigned>
            <length>8</length>
            <description>A unique running number to identify enrollment</description>
        </field>

        <field>
            <name>student_id</name>
            <type>integer</type>
            <notnull>0</notnull>
            <unsigned>1</unsigned>
            <length>8</length>
            <description>Foreign key refer to student</description>
        </field>

        <field>
            <name>course_id</name>
            <type>integer</type>
            <notnull>0</notnull>
            <unsigned>1</unsigned>
            <length>8</length>
            <description>Foreign key refer to course</description>
        </field>

        <index>
            <name>pk_enrollment</name>
            <unique>1</unique>
            <primary>1</primary>

            <field>
                <name>id</name>
                <sorting>ascending</sorting>
            </field>
        </index>

        <foreign>
            <name>fk_student_enrollment</name>
            <field>student_id</field>
            <references>
                <table>student</table>
                <field>id</field>
            </references>
            <ondelete>restrict</ondelete>
            <onupdate>cascade</onupdate>
        </foreign>
        <foreign>
            <name>fk_course_enrollment</name>
            <field>course_id</field>
            <references>
                <table>course</table>
                <field>id</field>
            </references>
            <ondelete>restrict</ondelete>
            <onupdate>cascade</onupdate>
        </foreign>
    </declaration>
</table>

Here is the error.

message: MDB2_Schema Error: schema validation error

Parser error: referenced table "student" of foreign key fk_student_enrollment" of table "enrollment" does not exist - No error - Byte: 2244; Line: 70; Col: 12

Js Lim
  • 3,625
  • 6
  • 42
  • 80

0 Answers0