【问题标题】:"SQLSTATE[23000]: Integrity constraint violation" in DoctrineDoctrine 中的“SQLSTATE [23000]:违反完整性约束”
【发布时间】:2011-02-25 03:13:59
【问题描述】:

虽然我真的不明白为什么,但我确实违反了 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

这是我的数据装置 (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

【问题讨论】:

    标签: zend-framework doctrine yaml database-integrity


    【解决方案1】:

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

    长话短说:不要在模型中定义同样存在于 yaml 架构中的变量!

    【讨论】:

      猜你喜欢
      • 2014-08-18
      • 2015-03-19
      • 2015-11-27
      • 2017-09-11
      • 2015-01-20
      • 2015-07-17
      • 2021-03-08
      • 2021-07-23
      相关资源
      最近更新 更多