我有这样的Symfony中的数据库模式:

Persona:
    actAs: { Timestampable: ~ }
    columns:
      primer_nombre:  { type: string(255), notnull: true }
      segundo_nombre: { type: string(255) }
      apellido:   { type: string(255), notnull: true }
      rut:         { type: string(255) }
      email:       { type: string(255) }
      email2:      { type: string(255) } 
      direccion:     { type: string(400) }
      ciudad:        { type: string(255) }
      region:      { type: string(255) }
      pais:     { type: string(255) }
      telefono:       { type: string(255) }
      telefono2:      { type: string(255) }
      fecha_nacimiento:   { type: date }

Alumno:
 inheritance:
    type:          concrete
    extends:       Persona
 columns:
  comentario:  { type: string(255) }
  estado_pago: { type: string(255) }

Alumno_Beca:
 columns:
  persona_id:   { type: integer, primary: true }
  beca_id: { type: integer, primary: true }
 relations:
  Alumno: { onDelete: CASCADE, local: persona_id, foreign: id } 
  Beca: { onDelete: CASCADE, local: beca_id, foreign: id } 

Beca:
 columns:
  nombre:        { type: string(255) }
  monto:      { type: double }
  porcentaje:  { type: double }
  descripcion: { type: string(5000) }

如您所见,“校友”具有“角色”的具体继承。现在,我正在尝试为这两个表创建固定装置,并且无法使学说加载它们。它给我这个错误:

SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败(eat/alumno__beca, ,约束 alumno__beca_persona_id_alumno_id外键(persona_id) 参考 alumno (id)删除级联)

有人知道如何编写从另一个继承的表格的固定装置吗?

谢谢!

有帮助吗?

解决方案

我不确定这是否是您的唯一问题,但是当为具有关系的表加载固定装置时,会以不违反其外键约束的顺序分别加载它们:第一父母,然后是孩子...而不是所有东西。如果您以这种方式定义了自己的关系,否则约束失败了,孩子记录就无法“合法地”存在。

其他提示

我在过去几周开始符合Symfony,今天对这些问题有问题。

第一个问题是,您的外国钥匙必须是整数。如果它是外键,则不要编写字段大小。而且您的代码也是正确的,这只是一个信息。

第二个问题是,您应该在数据库表上删除该外键索引。如果已经创建了它,则再次插入SQL时会出现错误。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top