Symfony 1.4 Propel:我定义了,但表中未定义外键
让我们看看这个架构:
orders:
_attributes: { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci }
id: ~
category_id: { type: integer, size: '10', required: true, defaultvalue: '0', foreigntable: categories, foreignreference: id }
whatisthis: { type: longvarchar, required: false }
categories:
_attributes: { phpName: Categories }
id: ~
name: { type: varchar, size: '255', required: true, defaultvalue: '' }
_uniques: { index_name: [name] }
我发现我的表中没有定义外键。我正在使用 innoDB,因此 PK 是可能的。或者 Propel 不应该设置外键?
Lets see this schema:
orders:
_attributes: { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci }
id: ~
category_id: { type: integer, size: '10', required: true, defaultvalue: '0', foreigntable: categories, foreignreference: id }
whatisthis: { type: longvarchar, required: false }
categories:
_attributes: { phpName: Categories }
id: ~
name: { type: varchar, size: '255', required: true, defaultvalue: '' }
_uniques: { index_name: [name] }
I figured out that the foreign keys are not defined in my tables. Im using innoDB
so PKs are possible. Or Propel isnt supposed to set foreign keys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“foreingtable”和“foreignreference”应该采用驼峰式大小写。并且category_id'的大小应该等于类别id的大小。
The "foreingtable" and "foreignreference" should be camel cased. And the category_id' size should be equal with the categories's id's size.
您使用的是哪个 symfony 和 propel 版本?
假设使用 Propel 1.x,这里是一个一对多关系示例:
说实话,我更喜欢手动创建数据库表(设置、索引、外键等),然后使用 symfony(假设您正在使用 Symfony 1.x) 任务来创建模式:
Which symfony and propel version are you using?
Supposing that are using Propel 1.x, here you are a one-many relationship example:
To be honest, I prefer to manually create the database tables (setting, indexes, foreign keys and so on) and then I use the symfony (assuming that you are using Symfony 1.x) task to create the schema: