Symfony 从模型生成数据库

发布于 2024-09-03 03:20:27 字数 2777 浏览 5 评论 0原文

我在生成简单的数据库表单模型时遇到问题。我正在使用:

  • Doctrine on Symfony 1.4.4
  • MySQL Workbench 5.2.16 with Doctrine Export 0.4.2dev

所以我的 ERL 模型是:

http://img708.imageshack.us/img708/1716/tmg.png

生成的 YAML 文件:

---
detect_relations: true
options:
  collate: utf8_unicode_ci
  charset: utf8
  type: InnoDB

Course:
  columns:
    id:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
    name:
      type: string(255)
      notnull: true
    keywords:
      type: string(255)
      notnull: true
    summary:
      type: clob(65535)
      notnull: true

Lecture:
  columns:
    id:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
    course_id:
      type: integer(4)
      primary: true
      notnull: true
    name:
      type: string(255)
      notnull: true
    description:
      type: string(255)
      notnull: true
    url:
      type: string(255)
  relations:
    Course:
      class: Course
      local: course_id
      foreign: id
      foreignAlias: Lectures
      foreignType: many
      owningSide: true

User:
  columns:
    id:
      type: integer(4)
      primary: true
      unique: true
      notnull: true
      autoincrement: true
    firstName:
      type: string(255)
      notnull: true
    lastName:
      type: string(255)
      notnull: true
    email:
      type: string(255)
      unique: true
      notnull: true
    designation:
      type: string(1024)
    personalHeadline:
      type: string(1024)
    shortBio:
      type: clob(65535)

UserCourse:
  tableName: user_has_course
  columns:
    user_id:
      type: integer(4)
      primary: true
      notnull: true
    course_id:
      type: integer(4)
      primary: true
      notnull: true
  relations:
    User:
      class: User
      local: user_id
      foreign: id
      foreignAlias: UserCourses
      foreignType: many
      owningSide: true
    Course:
      class: Course
      local: course_id
      foreign: id
      foreignAlias: UserCourses
      foreignType: many
      owningSide: true

无论如何我尝试在以下时间发生此错误:

symfony doctrine:build --all --no-confirmation

SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'user_userid' doesn't exist in table. Failing Query: "ALTER TABLE user_has_course ADD CONSTRAINT user_has_course_user_userid_user_id FOREIGN KEY (user_userid) REFERENCES user(id)". Failing Query: ALTER TABLE user_has_course ADD CONSTRAINT user_has_cou
rse_user_userid_user_id FOREIGN KEY (user_userid) REFERENCES user(id)

目前我正在学习 Symfony,并且遇到了此错误。请帮忙。

I am having troubles generating a simple database form model. I am using:

  • Doctrine on Symfony 1.4.4
  • MySQL Workbench 5.2.16 with Doctrine Export 0.4.2dev

So my ERL Model is:

http://img708.imageshack.us/img708/1716/tmg.png

Genereted YAML file:

---
detect_relations: true
options:
  collate: utf8_unicode_ci
  charset: utf8
  type: InnoDB

Course:
  columns:
    id:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
    name:
      type: string(255)
      notnull: true
    keywords:
      type: string(255)
      notnull: true
    summary:
      type: clob(65535)
      notnull: true

Lecture:
  columns:
    id:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
    course_id:
      type: integer(4)
      primary: true
      notnull: true
    name:
      type: string(255)
      notnull: true
    description:
      type: string(255)
      notnull: true
    url:
      type: string(255)
  relations:
    Course:
      class: Course
      local: course_id
      foreign: id
      foreignAlias: Lectures
      foreignType: many
      owningSide: true

User:
  columns:
    id:
      type: integer(4)
      primary: true
      unique: true
      notnull: true
      autoincrement: true
    firstName:
      type: string(255)
      notnull: true
    lastName:
      type: string(255)
      notnull: true
    email:
      type: string(255)
      unique: true
      notnull: true
    designation:
      type: string(1024)
    personalHeadline:
      type: string(1024)
    shortBio:
      type: clob(65535)

UserCourse:
  tableName: user_has_course
  columns:
    user_id:
      type: integer(4)
      primary: true
      notnull: true
    course_id:
      type: integer(4)
      primary: true
      notnull: true
  relations:
    User:
      class: User
      local: user_id
      foreign: id
      foreignAlias: UserCourses
      foreignType: many
      owningSide: true
    Course:
      class: Course
      local: course_id
      foreign: id
      foreignAlias: UserCourses
      foreignType: many
      owningSide: true

And no matter what I try this error occurs after:

symfony doctrine:build --all --no-confirmation

SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'user_userid' doesn't exist in table. Failing Query: "ALTER TABLE user_has_course ADD CONSTRAINT user_has_course_user_userid_user_id FOREIGN KEY (user_userid) REFERENCES user(id)". Failing Query: ALTER TABLE user_has_course ADD CONSTRAINT user_has_cou
rse_user_userid_user_id FOREIGN KEY (user_userid) REFERENCES user(id)

Currently I am studying Symfony, and stuck with this error. Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎会甘心 2024-09-10 03:20:27

正如错误中所述:“user.user_id”列不存在。在您的关系中,您指的是一个名为“user_id”的列,该列应该位于“user”表中,但您的用户表具有“id”列。

It's as it says in the error: the column "user.user_id" doesn't exist. In your relations, you're referring to a column called "user_id" that should be in the "user" table, but instead, your user table has the column "id".

鹤仙姿 2024-09-10 03:20:27

确保您的架构引擎使用 InnoDB,因为 MyISAM 和其他引擎不支持外键。

Make sure you are using InnoDB for your Schema's Engine as MyISAM and others doesn't support foreign keys.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文