2010-09-14 40 views
2

我正在构建一个schema.yml,我试图将外键约束添加到表sf_guard_user。但是,当我做doctrine:insert-sql(edit:doctrine:build --all)时,我的表和sf_guard_user之间的链接就不存在了!我错过了什么吗?使用sfDoctrineGuardPlugin的schema.yml

我用mysql(InnoDB的)和Symfony的1.4

这里是我的schema.yml样本:

Author: 
    connection: doctrine 
    tableName: ec_author 
    actAs: 
    Sluggable: 
     fields: [name] 
     unique: true 
     canUpdate: false 
    columns: 
    sf_guard_user_id: 
     type: integer 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: false 
    name: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    contents: 
     type: string() 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    relations: 
     User: 
     class: sfGuardUser 
     foreignType: one 
     local: sf_guard_user_id 
     foreign: id 

有到sfGuardUser没有任何联系,即使他们中描述的schema.yml: alt text alt text

+0

您使用的是什么数据库引擎? – greg0ire 2010-09-14 16:23:01

+0

我在Mysql上使用InnoDB。 – Manu 2010-09-17 10:10:23

+0

Manu,BaseAuthor类中存在关系吗?是否有打电话给$ this-> hasOne('sfGuardUser ...'? – 2010-09-18 16:18:36

回答

2

这一个工程:

Author: 
    connection: doctrine 
    tableName: ec_author 
    actAs: 
    Sluggable: 
     fields: [name] 
     unique: true 
     canUpdate: false 
    columns: 
    sf_guard_user_id: 
     type: integer 
     fixed: false 
     unsigned: false 
     primary: false 
     autoincrement: false 
    name: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    contents: 
     type: string() 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    relations: 
     User: 
     class: sfGuardUser 
     foreignType: one 
     local: sf_guard_user_id 
     foreign: id 
     foreignAlias: author 

sf_guard_user_id是一个外键,那么它可以” t是主键。所以我将 primary: true更改为primary: false

+0

顺便说一句,您的表ec_author中将有一个名为id的主键。它是自动生成的(如果您没有明确声明主键)。 – 2010-09-21 15:19:06

+0

它的工作原理!最后!我爱你 :) – Manu 2010-09-22 07:37:48

1

您应该重建模型和SQL也。试试运行:

symfony doctrine:build --all 

这将痛殴现有的所有数据。如果你不想这样做,你必须写一个迁移。

+0

+1 insert-sql只是插入schema.sql文件,如果你不重新生成它,它不会工作。 – greg0ire 2010-09-17 10:51:51

+0

即使构建 - 所有的链接都不存在。我应该改变插件内的schema.yml ? – Manu 2010-09-17 12:29:54

+0

当你说链接不存在时,它们在哪里丢失?它是否在SQL中丢失(即从sf_guard_user_id到sf_guard_user表中没有FK)?BaseAuthor是否将sf_guard_user_id添加到用户的关系? – 2010-09-17 14:37:01

1

在您的模式文件中打开相应的表时,类名称需要与您指定的名称相同。

因此,举例来说,使用的是:

relations: 
    User: 
     class: sfGuardUser 
     foreignType: one 

类的名字在这里必须sfGuardUser表的声明相匹配。只要确定他们是一样的。有时候,它可以被声明为sf_guard_user。

如果是罚款,你可以尝试增加一些定义你的关系条目:

relations: 
    User: 
     class: sfGuardUser 
     foreignType: one 
     local: sf_guard_user_id 
     foreign: sf_guard_user_id 
+0

感谢您的回答,我已经添加了您的建议,但链接仍然不存在:( – Manu 2010-09-21 13:12:39

+0

能够填充表格?当您尝试添加不存在的FK时,是否会导致FK错误? – jgallant 2010-09-21 13:29:18

相关问题