Symfony1 条令:build--model--sql可以,但条令:insert-sql不行。你知道为什么吗?
以下是我的schema.yml文件:Symfony1 条令:build--model--sql可以,但条令:insert-sql不行。你知道为什么吗?,symfony1,model,doctrine,schema,symfony-1.4,Symfony1,Model,Doctrine,Schema,Symfony 1.4,以下是我的schema.yml文件: issues: actAs: { Timestampable: ~ } columns: issueId: { type: integer(4), notnull: true, primary: true, autoincrement: true } issueDateForPublish: { type: timestamp, notnull: true } issueName: { type: string(255),
issues:
actAs: { Timestampable: ~ }
columns:
issueId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
issueDateForPublish: { type: timestamp, notnull: true }
issueName: { type: string(255), notnull: true }
issueCoverArticleId: { type: integer(4), notnull: true }
relations:
articles:
class: articles
foreignAlias: article
local: articleId
foreign: issueId
type: many
articles:
actAs: { Timestampable: ~ }
columns:
articleId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
articleTitle: { type: string(), notnull: true }
articleText: { type: string(), notnull: true }
articleDataForPublish: { type: timestamp, notnull: true }
articleIsDraft: { type: boolean, notnull: true, default: 1 }
articleIsOnHold: { type: boolean, notnull: true, default: 0 }
articleIsModerate: { type: boolean, notnull: true, default: 0 }
articleIsApprove: { type: boolean, notnull: true, default: 0 }
relations:
articles:
local: issueId
foreign: articleId
onDelete: cascade
comments:
class: comments
foreignAlias: comment
local: commentId
foreign: articleId
type: many
comments:
actAs: { Timestampable: ~ }
columns:
commentId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
commentName: { type: string(255), notnull: true }
commentSurname: { type: string(255), notnull: true }
commentMail: { type: string(255), notnull: true }
commentDataForPublish: { type: timestamp }
commentIsModerated: { type: boolean, notnull: true, default: 0 }
commentIsApprove: { type: boolean, notnull: true, default: 0 }
relations:
articles:
local: articleId
foreign: commentId
onDelete: cascade
同样,当我运行php-symfony-doctrine:build--model和php-symfony-doctrine:build--sql时,没有任何问题。“php symfony原则:插入sql”导致以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'issueid' doesn't exist in table. Failing Query: "CREATE TABLE articles (articleid INT AUTO_INCREMENT, articletitle TEXT NOT NULL, articletext TEXT NOT NULL, articledataforpublish DATETIME NOT NULL, articleisdraft TINYINT(1) DEFAULT '1' NOT NULL, articleisonhold TINYINT(1) DEFAULT '0' NOT NULL, articleismoderate TINYINT(1) DEFAULT '0' NOT NULL, articleisapprove TINYINT(1) DEFAULT '0' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX issueid_idx (issueid), PRIMARY KEY(articleid)) ENGINE = INNODB". Failing Query: CREATE TABLE articles (articleid INT AUTO_INCREMENT, articletitle TEXT NOT NULL, articletext TEXT NOT NULL, articledataforpublish DATETIME NOT NULL, articleisdraft TINYINT(1) DEFAULT '1' NOT NULL, articleisonhold TINYINT(1) DEFAULT '0' NOT NULL, articleismoderate TINYINT(1) DEFAULT '0' NOT NULL, articleisapprove TINYINT(1) DEFAULT '0' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX issueid_idx (issueid), PRIMARY KEY(articleid)) ENGINE = INNODB
谢谢你的帮助,厄曼。你的定义有点错误 Local应该是当前表中字段的名称,foreign应该是foreign表中字段的名称-这些名称的顺序是错误的 您通常只定义关系的一端-doctrine自动将相反的值添加到另一个表中,并且在99%的时间内都正确。如果您手动执行,它们必须匹配。在这种情况下,从问题中删除文章关系,从文章中删除评论关系 评论没有文章id字段 不需要外部别名,但您使用的方式不对-它是当前表/对象在关系远端的表/对象中的引用方式。默认为当前对象的名称,因此通常可以忽略 几乎没有其他的小麻烦。猜测一下,我认为这个模式可以帮助您:
issue:
actAs: { Timestampable: ~ }
columns:
issueId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
issueDateForPublish: { type: timestamp, notnull: true }
issueName: { type: string(255), notnull: true }
issueCoverArticleId: { type: integer(4), notnull: true }
article:
actAs: { Timestampable: ~ }
columns:
articleId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
articleTitle: { type: string(), notnull: true }
articleText: { type: string(), notnull: true }
articleDataForPublish: { type: timestamp, notnull: true }
articleIsDraft: { type: boolean, notnull: true, default: 1 }
articleIsOnHold: { type: boolean, notnull: true, default: 0 }
articleIsModerate: { type: boolean, notnull: true, default: 0 }
articleIsApprove: { type: boolean, notnull: true, default: 0 }
issueId: { type: integer(4) }
relations:
issue:
local: issueId
foreign: issueId
foreignAlias: articles
onDelete: cascade
comment:
actAs: { Timestampable: ~ }
columns:
commentId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
commentName: { type: string(255), notnull: true }
commentSurname: { type: string(255), notnull: true }
commentMail: { type: string(255), notnull: true }
commentDataForPublish: { type: timestamp }
commentIsModerated: { type: boolean, notnull: true, default: 0 }
commentIsApprove: { type: boolean, notnull: true, default: 0 }
articleId: { type: integer(4) }
relations:
article:
local: articleId
foreign: articleId
onDelete: cascade
foreignAlias: comments
你的定义有点错误 Local应该是当前表中字段的名称,foreign应该是foreign表中字段的名称-这些名称的顺序是错误的 您通常只定义关系的一端-doctrine自动将相反的值添加到另一个表中,并且在99%的时间内都正确。如果您手动执行,它们必须匹配。在这种情况下,从问题中删除文章关系,从文章中删除评论关系 评论没有文章id字段 不需要外部别名,但您使用的方式不对-它是当前表/对象在关系远端的表/对象中的引用方式。默认为当前对象的名称,因此通常可以忽略 几乎没有其他的小麻烦。猜测一下,我认为这个模式可以帮助您:
issue:
actAs: { Timestampable: ~ }
columns:
issueId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
issueDateForPublish: { type: timestamp, notnull: true }
issueName: { type: string(255), notnull: true }
issueCoverArticleId: { type: integer(4), notnull: true }
article:
actAs: { Timestampable: ~ }
columns:
articleId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
articleTitle: { type: string(), notnull: true }
articleText: { type: string(), notnull: true }
articleDataForPublish: { type: timestamp, notnull: true }
articleIsDraft: { type: boolean, notnull: true, default: 1 }
articleIsOnHold: { type: boolean, notnull: true, default: 0 }
articleIsModerate: { type: boolean, notnull: true, default: 0 }
articleIsApprove: { type: boolean, notnull: true, default: 0 }
issueId: { type: integer(4) }
relations:
issue:
local: issueId
foreign: issueId
foreignAlias: articles
onDelete: cascade
comment:
actAs: { Timestampable: ~ }
columns:
commentId: { type: integer(4), notnull: true, primary: true, autoincrement: true }
commentName: { type: string(255), notnull: true }
commentSurname: { type: string(255), notnull: true }
commentMail: { type: string(255), notnull: true }
commentDataForPublish: { type: timestamp }
commentIsModerated: { type: boolean, notnull: true, default: 0 }
commentIsApprove: { type: boolean, notnull: true, default: 0 }
articleId: { type: integer(4) }
relations:
article:
local: articleId
foreign: articleId
onDelete: cascade
foreignAlias: comments
非常感谢你的回答。它非常有用。我的想法就像当地外企的第一把外键。现在我明白了,不是这样的。(;我还学到了更多的东西。再次感谢benlumley!非常感谢你的回答。它太有用了。我一直在想本地外文的primery外键。现在我明白它不是。(;我还学到了更多的东西。再次感谢benlumley!