“SQLSTATE[23000]:违反完整性约束”在教义中
我确实违反了原则的完整性约束,尽管我真的不明白为什么。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我发现了问题。
此错误的原因是我已经更改了 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!