Doctrine 在Symfony中使用YAML创建的关系(使用条令)不会填充到MySQL数据库中
我是Symfony的新手,尝试通过构建模型创建数据库结构,然后构建sql 所有表都显示在数据库中,但不会创建简单的一对多关系以外的关系 例如,我有一个存储公司的表,它们可以是供应商或客户,我有另一个存储客户/供应商关系的表Doctrine 在Symfony中使用YAML创建的关系(使用条令)不会填充到MySQL数据库中,doctrine,yaml,symfony1,Doctrine,Yaml,Symfony1,我是Symfony的新手,尝试通过构建模型创建数据库结构,然后构建sql 所有表都显示在数据库中,但不会创建简单的一对多关系以外的关系 例如,我有一个存储公司的表,它们可以是供应商或客户,我有另一个存储客户/供应商关系的表 Identifier: actAs: [Timestampable] tableName: identifier columns: id: type: integer(20) fixed: false unsigned:
Identifier:
actAs: [Timestampable]
tableName: identifier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
relations:
Suppliers:
class: Identifier
local: customer_id
foreign: supplier_id
refClass: CustomerSupplier
foreignAlias: Customers
onDelete: CASCADE
Customers:
class: Identifier
local: supplier_id
foreign: customer_id
refClass: CustomerSupplier
foreignAlias: Suppliers
onDelete: CASCADE
CustomerSupplier:
actAs: [Timestampable]
tableName: customerSupplier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
customer_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
supplier_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
也不会创建一对一关系:
IdentifierExtCompany:
actAs: [Timestampable]
tableName: identifierExtCompany
columns:
identifier_id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
relations:
Identifier:
local: identifier_id
foreign: id
onDelete: CASCADE
foreignType: one
type: one
当我运行BuildSQL生成的sql请求时,所有这些关系都不会出现在数据库中
你能帮我找出yaml文件中的错误吗?提前谢谢
例如,我有一个存储公司的表,它们可以是供应商或客户,我有另一个存储客户/供应商关系的表
Identifier:
actAs: [Timestampable]
tableName: identifier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
relations:
Suppliers:
class: Identifier
local: customer_id
foreign: supplier_id
refClass: CustomerSupplier
foreignAlias: Customers
onDelete: CASCADE
Customers:
class: Identifier
local: supplier_id
foreign: customer_id
refClass: CustomerSupplier
foreignAlias: Suppliers
onDelete: CASCADE
CustomerSupplier:
actAs: [Timestampable]
tableName: customerSupplier
columns:
id:
type: integer(20)
fixed: false
unsigned: false
primary: true
autoincrement: true
customer_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
supplier_id:
type: integer(20)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
似乎您还必须为客户供应商定义关系:
relations:
IdentifierAlias:
class: Identifier
local: identifier_id
onDelete: CASCADE
SupplierAlias:
class: Supplier
local: supplier_id
onDelete: CASCADE
也不会创建一对一关系
尝试在关系中指定class
属性,并将其设置为Identifier
希望这有帮助。您正在使用MyISAM吗?MySQL中的“关系”到底叫什么?外键?M桌子?谢谢你的回复,我找到了一个解决办法。不知道为什么,当我运行原则:构建模型
,然后运行原则:构建sql
和原则:插入sql
时,关系没有正确填充。当我运行doctrine:build--all--no-confirmation时,它运行得很好