【发布时间】:2023-03-06 17:27:01
【问题描述】:
我在我的 Symfony 项目中使用 doctrine,通过连接到已经存在的 postgres 数据库。
数据库有几个模式,但 symfony 应用程序只使用它自己的模式。我创建的第一个Entity 类如下:
namespace Belka\TestBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="app_auth.User", schema="app_auth")
*/
class User {
/**
* @ORM\Column(type="string")
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
*/
private $username;
/**
* @ORM\Column(type="string")
*/
private $email;
/**
* @ORM\Column(type="string")
*/
private $password;
}
如您所见,Entity 指定了自己的架构app_auth。
接下来,我尝试使用迁移包。因此,我安装并配置了它,以便只考虑我的架构:
config.yml 的摘录:
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
schema_filter: ~^app_auth\..*~
config_dev.yml 的摘录:
doctrine_migrations:
dir_name: "%kernel.root_dir%/../.container/update/DoctrineMigrations"
namespace: Application\Migrations
table_name: "app_auth.migration_versions"
name: Application Migrations
然后我运行 diff:
php app/console doctrine:migrations:diff
很遗憾,生成的迁移类如下:
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160422171409 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE SCHEMA app_auth');
}
}
那我的配置有什么问题?
【问题讨论】:
-
您看到的是哪个错误消息?
-
我没有收到任何错误。它实际上似乎忽略了实体。我自己创建了表格并再次运行
migrations:diff:我得到的是一个空的up和一个带有DROP 表格的down -
@Bertuz 我面临同样的问题。我知道您的帖子很旧,但是您找到解决方案了吗?
-
不,如果我没记错的话,我是手工完成的。把它们写在 github 上怎么样?
-
我仍然在发生这种情况。 Symfony 5.1。
标签: postgresql symfony doctrine-orm doctrine-migrations