使用以下命令生成表格时遇到问题:
php symfony doctrine:insert-sql
它返回以下错误:
>> doctrine creating tables
Class "Complaint" must be a child class of Doctrine_Record
PHP Fatal error: Call to a member function evictAll() on a non-object in D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctri
nePlugin\lib\vendor\doctrine\Doctrine\Connection.php on line 1239
PHP Stack trace:
PHP 1. {main}() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\symfony:0
PHP 2. include() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\symfony:14
PHP 3. sfDatabaseManager->shutdown() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\database\sfDatabaseManager.class.php:0
PHP 4. sfDoctrineDatabase->shutdown() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\database\sfDatabaseManager.class.php:134
PHP 5. Doctrine_Manager->closeConnection() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\database\sfDoctr
ineDatabase.class.php:165
PHP 6. Doctrine_Connection->close() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrin
e\Manager.php:580
PHP 7. Doctrine_Connection->clear() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrin
e\Connection.php:1268
这是我的schema.yml,我用它来生成模型(php symfony doctrine:build-mdeol):
InspectionReport:
actAs: { Timestampable: ~ }
columns:
customer_id: { type: integer(5), notnull: true }
username: { type: string(255), notnull: true }
start_time: { type: string(5) }
end_time: { type: string(5) }
type: { type: string(5) }
reason: { type: string(4) }
contact: { type: string(5) }
subject: { type: string(5) }
remarks: { type: string(5000) }
emailaddresses: { type: string(5) }
relations:
Complaints:
class: Complaint
refClass: ComplaintInspectionReport
local: id
foreign: complaint_id
Reviews:
class: Review
refClass: ReviewInspectionReport
local: id
foreign: review_id
ComplaintInspectionReport:
columns:
complaint_id: { type: integer(4), primary: true }
inspection_report_id: { type: integer, primary: true }
relations:
Complaint: { onDelete: CASCADE, local: complaint_id, foreign: id }
InspectionReport: { onDelete: CASCADE, local: inspection_report_id, foreign: id }
ReviewInspectionReport:
columns:
review_id: { type: integer, primary: true }
inspection_report_id: { type: integer, primary: true }
relations:
Review: { onDelete: CASCADE, local: review_id, foreign: id }
InspectionReport: { onDelete: CASCADE, local: inspection_report_id, foreign: id }
Complaint:
columns:
id: { type: integer, notnull: true }
description: { type: string(32), notnull: true }
contact: { type: string(32) }
remark: { type: string(50) }
Review:
columns:
id: { type: integer, notnull: true }
description: { type: string(32), notnull: true }
contact: { type: string(32) }
remark: { type: string(50) }
grade: { type: string(1) }
email_address: { type: string(32) }
我从模型/模式生成的schema.sql(php symfony doctrine:build-sql):
CREATE TABLE complaint (id BIGINT AUTO_INCREMENT, description VARCHAR(32) NOT NULL, contact VARCHAR(32), remark VARCHAR(50), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE complaint_inspection_report (complaint_id INT, inspection_report_id BIGINT, PRIMARY KEY(complaint_id, inspection_report_id)) ENGINE = INNODB;
CREATE TABLE inspection_report (id BIGINT AUTO_INCREMENT, customer_id BIGINT NOT NULL, username VARCHAR(255) NOT NULL, start_time VARCHAR(5), end_time VARCHAR(5), type VARCHAR(5), reason VARCHAR(4), contact VARCHAR(5), subject VARCHAR(5), remarks TEXT, emailaddresses VARCHAR(5), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE review (id BIGINT AUTO_INCREMENT, description VARCHAR(32) NOT NULL, contact VARCHAR(32), remark VARCHAR(50), grade VARCHAR(1), email_address VARCHAR(32), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE review_inspection_report (review_id BIGINT, inspection_report_id BIGINT, PRIMARY KEY(review_id, inspection_report_id)) ENGINE = INNODB;
ALTER TABLE complaint_inspection_report ADD CONSTRAINT complaint_inspection_report_complaint_id_complaint_id FOREIGN KEY (complaint_id) REFERENCES complaint(id) ON DELETE CASCADE;
ALTER TABLE complaint_inspection_report ADD CONSTRAINT ciii FOREIGN KEY (inspection_report_id) REFERENCES inspection_report(id) ON DELETE CASCADE;
ALTER TABLE review_inspection_report ADD CONSTRAINT riii FOREIGN KEY (inspection_report_id) REFERENCES inspection_report(id) ON DELETE CASCADE;
ALTER TABLE review_inspection_report ADD CONSTRAINT review_inspection_report_review_id_review_id FOREIGN KEY (review_id) REFERENCES review(id) ON DELETE CASCADE;
如果我手动运行SQL它工作正常,但是当使用doctrine:insert-sql时它会返回错误。
我正在考虑我的架构中的错误,但似乎无法掌握它。或许它可能完全不同。
答案 0 :(得分:1)
我错了,我刚刚生成了类,并没有尝试加载sql。
实际上你几乎没有错误:
id
,只要你不需要它来主键,不增加等等。否则会给Doctrine带来麻烦ComplaintInspectionReport
& ReviewInspectionReport
),您无需重新定义relations
。如果在父类中正确定义它们,则不需要它们integer
类型。 Doctrine将始终使用integer
,但是如果您定义一个带有integer(4)
的外来导致由Doctrine自动生成的id,则插入sql时该关系将失败。因为一边是integer
,另一边是integer(4)
。local
中定义的InspectionReport
密钥。您使用id
两次,但您必须为中间表定义本地密钥,而不是当前密钥。因此,您必须为两者设置inspection_report_id
。这是固定架构:
InspectionReport:
actAs: { Timestampable: ~ }
columns:
customer_id: { type: integer(5), notnull: true }
username: { type: string(255), notnull: true }
start_time: { type: string(5) }
end_time: { type: string(5) }
type: { type: string(5) }
reason: { type: string(4) }
contact: { type: string(5) }
subject: { type: string(5) }
remarks: { type: string(5000) }
emailaddresses: { type: string(5) }
relations:
Complaints:
class: Complaint
refClass: ComplaintInspectionReport
local: inspection_report_id
foreign: complaint_id
Reviews:
class: Review
refClass: ReviewInspectionReport
local: inspection_report_id
foreign: review_id
ComplaintInspectionReport:
columns:
complaint_id: { type: integer, primary: true }
inspection_report_id: { type: integer, primary: true }
ReviewInspectionReport:
columns:
review_id: { type: integer, primary: true }
inspection_report_id: { type: integer, primary: true }
Complaint:
columns:
description: { type: string(32), notnull: true }
contact: { type: string(32) }
remark: { type: string(50) }
Review:
columns:
description: { type: string(32), notnull: true }
contact: { type: string(32) }
remark: { type: string(50) }
grade: { type: string(1) }
email_address: { type: string(32) }
在尝试重新插入sql之前,请不要忘记清除缓存。