2010-05-25 284 views
1

我有麻煩生成一個簡單的數據庫表單模型。我使用:Symfony從模型生成數據庫

  • 學說上的Symfony 1.4.4
  • MySQL工作臺5.2.16與學說出口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,堅持了這個錯誤。請幫忙。

回答

1

正如它在錯誤中所述:「user.user_id」列不存在。在你的關係中,你指的是一個名爲「user_id」的列應該在「user」表中,但是你的用戶表具有「id」列。

0

請確保您使用InnoDB作爲您的架構引擎作爲MyISAM,而其他人不支持外鍵。

相關問題