“SQLSTATE[23000]:违反完整性约束”在教义中

发布于 2024-09-04 01:52:48 字数 1208 浏览 6 评论 0原文

我确实违反了原则的完整性约束,尽管我真的不明白为什么。

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

i do get an Integrity constraint violation for Doctrine though i really can't see why.

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

And here's my data 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

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

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

发布评论

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

评论(1

云巢 2024-09-11 01:52:49

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

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

Okay, i found the Problem.
The Reason for this Error was that i already altered the Model_User and added an Attribute "owner" and then Doctrine tried to add the already existing attribute to the Model.

Long Story short: Do not define variables in your Models that do exist in your yaml schema as well!

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