我有一個問題,是否有人遇到過這種問題。我一直在尋找解決方案,但我沒有找到。
每次我用學說生成遷移時,我都會在遷移檔案中看到:
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE verification ALTER id TYPE UUID');
$this->addSql('ALTER TABLE verification ALTER id DROP DEFAULT');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE verification ALTER verification_id TYPE UUID');
$this->addSql('ALTER TABLE verification ALTER verification_id DROP DEFAULT');
}
這些是我的注釋:
use Ramsey\Uuid\Doctrine\UuidGenerator;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*
* @Groups({"read"})
**/
private UuidInterface $id;
我使用 postgress 影像:postgres:13-alpine 和 "doctrine/doctrine-migrations-bundle": "^3.0",
框架“api-platform/core”:“^2.6”,
我已經嘗試過以前版本的學說遷移捆綁包以及 postgres:12
每次遷移都會添加這些更改。我檢查了我的本地資料庫,洗掉它,洗掉 docker 卷。然后我再次啟動容器,運行遷移以確保我獲得了正確的資料庫架構。問題仍然存在。我不知道是什么原因導致這個問題。也許你們中的一些人知道我可以尋找什么?
uj5u.com熱心網友回復:
您的 composer.lock 中可能有 1.7.0 版本的 ramsey/uuid-doctrine 擴展,因為它確實存在生成模式的錯誤。幾天前已修復:https : //github.com/ramsey/uuid-doctrine/pull/165
所以嘗試降級到 1.6.0:
composer require ramsey/uuid-doctrine:1.6.0
(或升級到最新的開發版本)
解釋
原則不斷生成遷移以更改 uuid 列的原因是自定義型別類(即Ramsey\Uuid\Doctrine\UuidType)錯過了 requiresSQLCommentHint 標志(在 1.7.0 中):
/**
* {@inheritdoc}
*
* @param AbstractPlatform $platform
*
* @return bool
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
這個標志告訴教義使用欄位上的注釋來確定需要將來自該欄位的值添加到哪種自定義型別中。在 Ramsey UuidType 的情況下,注釋應如下所示:(DC2Type:uuid)
作為一種快速解決方法,您甚至可以手動添加注釋(無需升級 ramsey/uuid-doctrine 包):
COMMENT ON COLUMN verification.id IS '(DC2Type:uuid)'
或通過遷移:
$this->addSql('COMMENT ON COLUMN verification.id IS \'(DC2Type:uuid)\'');
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/343625.html
