DocSTine中的“SQLSTATE [23000]:完整性约束违规”

时间:2010-05-28 13:20:00

标签: zend-framework doctrine yaml database-integrity

虽然我真的看不出原因,但我确实对Doctrine有了严重的约束违规行为。

的schema.yml

User:
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    username:
      type: varchar(64)
      notnull: true
    email:
      type: varchar(128)
      notnull: true
    password:
      type: varchar(128)
      notnull: true
  relations:
    Websites:
      class: Website
      local: id
      foreign: owner
      type: many
      foreignType: one
      onDelete: CASCADE

Website:
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    active:
      type: bool
    owner:
      type: integer
      notnull: true
    plz:
      type: integer
      notnull: true
    longitude:
      type: double(10,6)
      notnull: true
    latitude:
      type: double(10,6)
      notnull: true
  relations:
    Owner:
      type: one
      foreignType: many
      class: User
      local: owner
      foreign: id

这是我的数据Fixtures(data.yml)

Model_User:
  User_1:
    username: as
    email: as****.com
    password: *****

Model_Website:
  Website_1:
    active: true
    plz: 34222
    latitude: 13.12
    longitude: 3.56
    Owner: User_1

1 个答案:

答案 0 :(得分:0)

好的,我找到了问题。 出现此错误的原因是我已经更改了Model_User并添加了属性“ owner ”,然后Doctrine尝试将已存在的属性添加到模型中。

长话短说:不要在模型中定义yaml模式中存在的变量!

相关问题