我正在做一个使用MDB2实现的项目。
我想在xml架构文件上设置外键。 只有3个表:学生,课程和注册,其中注册作为桥梁实体。
这是我的注册xml文件。
<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>
这是错误。
消息:MDB2_Schema错误:架构验证错误
解析器错误:引用表“学生”的外键fk_student_enrollment“表”注册“不存在 - 没有错误 - 字节:2244;行:70;作品:12