doctrine:build --model和--sql ok但是doctrine:insert-sql不是。你知道为什么吗?

时间:2011-01-12 15:05:24

标签: 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), 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 doctrine:insert-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

感谢您的帮助,erman。

1 个答案:

答案 0 :(得分:3)

你的定义有点不对。

Local应该是当前表中字段的名称,而外部表中的字段是外来的 - 你有这些错误的方法。

您通常只定义关系的一端 - doctrine auto将反向添加到另一个表中,并在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