这个错误的流量迁移代码和新域有什么问题?我尝试迁移时遇到sql错误。看起来像一个简单的新域,它将允许我定义一个新的产品类型 - 一个套件 - 将被定义为具有从其他产品中提取的组件 - 在我简单的旧SQL中认为结果表只是几个外键(一个到套件产品,一个到sku(一个产品项目的集合),从中绘制一个组件产品)和一个数量字段,用于说明从相应的sku中抽取多少项目,当然很多行可以链接到相同的产品表明给定的套件可以由多种类型的产品制成。
新域名:
<?php
namespace SeeThroughWeb\Shop\Domain\Model;
/* *
* This script belongs to the TYPO3 Flow package "SeeThroughWeb.Shop". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
use Doctrine\ORM\Mapping as ORM;
/**
* A Kit
*
* @Flow\Entity
*/
class Kit {
/**
* The product
* @var \SeeThroughWeb\Shop\Domain\Model\Product
* @ORM\ManyToOne(cascade={"persist"})
*/
protected $product ;
/**
* The product article
* @var \SeeThroughWeb\Shop\Domain\Model\ProductArticle
* @ORM\ManyToOne(cascade={"persist"})
*/
protected $productArticle;
/**
* The quantity
* @var integer
*/
protected $quantity;
/**
* The creation date
* @var \DateTime
*/
protected $creationDate;
/**
* The Constructor for Kit
*/
public function __construct() {
$this->creationDate = new \DateTime();
$this->quantity = 0;
}
/**
* Get the Kit's product article
*
* @return \SeeThroughWeb\Shop\Domain\Model\ProductArticle The Kit's product article
*/
public function getProductArticle() {
return $this->productArticle;
}
/**
* Sets this Kit's product article
*
* @param \SeeThroughWeb\Shop\Domain\Model\ProductArticle $productArticle The Kit's product article
* @return void
*/
public function setProductArticle($productArticle) {
$this->productArticle = $productArticle;
}
/**
* Get the product
*
* @return \SeeThroughWeb\Shop\Domain\Model\Product The product
*/
public function getProduct () {
return $this->product ;
}
/**
* Sets this Kits product
*
* @param \SeeThroughWeb\Shop\Domain\Model\Product $product The kits product
* @return void
*/
public function setProduct ($product ) {
$this->product = $product ;
}
/**
* Get the Kit's quantity
*
* @return integer The Kit's quantity
*/
public function getQuantity() {
return $this->quantity;
}
/**
* Sets this Kit's quantity
*
* @param integer $quantity The Kit's quantity
* @return void
*/
public function setQuantity($quantity) {
$this->quantity = $quantity;
}
}
?>
迁移代码:
<?php
namespace TYPO3\Flow\Persistence\Doctrine\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration,
Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your need!
*/
class Version20150105162605 extends AbstractMigration {
/**
* @param Schema $schema
* @return void
*/
public function up(Schema $schema) {
// this up() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
$this->addSql("CREATE TABLE seethroughweb_shop_domain_model_kit (persistence_object_identifier VARCHAR(40) NOT NULL, product VARCHAR(40) DEFAULT NULL, productarticle VARCHAR(40) DEFAULT NULL, quantity INT NOT NULL, creationdate DATETIME NOT NULL, INDEX IDX_3E2E11A6D34A04AD (product), INDEX IDX_3E2E11A69975A841 (productarticle), PRIMARY KEY(persistence_object_identifier)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("ALTER TABLE seethroughweb_shop_domain_model_kit ADD CONSTRAINT FK_3E2E11A6D34A04AD FOREIGN KEY (product) REFERENCES seethroughweb_shop_domain_model_product (persistence_object_identifier)");
$this->addSql("ALTER TABLE seethroughweb_shop_domain_model_kit ADD CONSTRAINT FK_3E2E11A69975A841 FOREIGN KEY (productarticle) REFERENCES seethroughweb_shop_domain_model_productarticle (persistence_object_identifier)");
}
/**
* @param Schema $schema
* @return void
*/
public function down(Schema $schema) {
// this down() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
$this->addSql("DROP TABLE seethroughweb_shop_domain_model_kit");
}
}
迁移尝试产生了这个:
Uncaught Exception
An exception occurred while executing 'ALTER TABLE
seethroughweb_shop_domain_model_kit ADD CONSTRAINT FK_3E2E11A6D34A04AD
FOREIGN KEY (product) REFERENCES seethroughweb_shop_domain_model_product
(persistence_object_identifier)':
SQLSTATE[HY000]: General error: 1005 Can't create table
'shop_epiexpert.#sql-611c_66d3' (errno: 150)
More Information
Exception code #0
File /home/epiexpert/domains/shop.epiexpert.com/public_html/releases/20131219160416/Packages/Libraries/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 47
新表确实已创建,并且在mysql workbench中看起来没问题。我猜测@ORM选择有什么不对,但不确定是什么,我已经尝试了其他一些但是到目前为止还没有运气,我对Doctrine和Typo3-Flow很新。
由于
附录1:结果表定义:
CREATE TABLE `seethroughweb_shop_domain_model_kit` (
`persistence_object_identifier` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`product` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
`productarticle` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
`quantity` int(11) NOT NULL,
`creationdate` datetime NOT NULL,
PRIMARY KEY (`persistence_object_identifier`),
KEY `IDX_3E2E11A6D34A04AD` (`product`),
KEY `IDX_3E2E11A69975A841` (`productarticle`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
哪个看起来对我来说,为什么错误呢?那些钥匙对吗?是否有一些其他表被创建来支持它们?可能有权限/权限问题? 当我在mysql workbench中输入Alter table命令时,我得到了同样的错误。
这是产品的创建表:
CREATE TABLE `seethroughweb_shop_domain_model_product` (
`persistence_object_identifier` varchar(40) NOT NULL,
`brand` varchar(40) DEFAULT NULL,
`primarycategory` varchar(40) DEFAULT NULL,
`createdby` varchar(40) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`description` varchar(4095) DEFAULT NULL,
`creationdate` datetime NOT NULL,
`status` int(11) NOT NULL,
`facebookpublish` int(11) DEFAULT NULL,
`twitterpublish` int(11) DEFAULT NULL,
`deleted` int(11) DEFAULT NULL,
`isfeatured` tinyint(1) DEFAULT NULL,
`countryofmanufacture` varchar(40) DEFAULT NULL,
`issenderproducerindicator` tinyint(1) DEFAULT NULL,
`video` varchar(255) DEFAULT NULL,
`availableregion` varchar(40) DEFAULT NULL,
PRIMARY KEY (`persistence_object_identifier`),
UNIQUE KEY `flow_identity_seethroughweb_shop_domain_model_product` (`name`),
KEY `IDX_7AF89F541C52F958` (`brand`),
KEY `IDX_7AF89F54B99DBC88` (`primarycategory`),
KEY `IDX_7AF89F5446D262E0` (`createdby`),
KEY `IDX_7AF89F541FEA467` (`countryofmanufacture`),
KEY `IDX_7AF89F54AE3174AD` (`availableregion`),
CONSTRAINT `FK_7AF89F541C52F958` FOREIGN KEY (`brand`) REFERENCES `seethroughweb_shop_domain_model_brand` (`persistence_object_identifier`),
CONSTRAINT `FK_7AF89F541FEA467` FOREIGN KEY (`countryofmanufacture`) REFERENCES `seethroughweb_shop_domain_model_country` (`persistence_object_identifier`),
CONSTRAINT `FK_7AF89F5446D262E0` FOREIGN KEY (`createdby`) REFERENCES `typo3_flow_security_account` (`persistence_object_identifier`),
CONSTRAINT `FK_7AF89F54AE3174AD` FOREIGN KEY (`availableregion`) REFERENCES `seethroughweb_shop_domain_model_currency` (`persistence_object_identifier`),
CONSTRAINT `FK_7AF89F54B99DBC88` FOREIGN KEY (`primarycategory`) REFERENCES `seethroughweb_shop_domain_model_productcategory` (`persistence_object_identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8