Sergej Brazdeikis
Sergej Brazdeikis

Reputation: 1373

Symfony generating database from model

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

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.

Upvotes: 1

Views: 1379

Answers (2)

Tom
Tom

Reputation: 30698

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".

Upvotes: 1

Marco Ceppi
Marco Ceppi

Reputation: 7722

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

Upvotes: 0

Related Questions