如何设置外键?
我正在做一个使用 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 错误:模式验证错误
解析器错误:表“enrollment”的外键 fk_student_enrollment”引用的表“student”不存在 - 无错误 - 字节:2244;行:70;列:12
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论