无法访问版本"latest",没有注册的迁移



所以我正在设置一个Symfony 5项目,并运行以下命令来从这样的实体注释生成数据库:

php bin/console doctrine:schema:validate
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

但它并没有像预期的那样工作,相反,我得到了这个错误:

**[ERROR]** The version "latest" couldn't be reached, there are no registered migrations.

diff命令正确地生成了包含up((和down((函数的迁移文件,但是当我随后运行migrate指令生成数据库时,它会失败,并出现上述错误。

我还注意到文件/config/packages/doctrine_migrations.yml最近更改为:

doctrine_migrations:
migrations_paths:
'AppMigrations': '%kernel.project_dir%/src/Migrations'

然而,学说似乎正在这条路径之外寻找以下路径中的迁移:

'%kernel.project_dir%/migrations'

如何解决上述错误,使migrate命令按预期工作,并从生成的迁移文件中生成数据库表?

php bin/console debug:config doctrine_migrations

Current configuration for extension with alias "doctrine_migrations"
=================================================================    ===
doctrine_migrations:
migrations_paths:
AppMigrations: /var/www/src/Migrations
services: {  }
factories: {  }
storage:
table_storage:
table_name: null
version_column_name: null
version_column_length: null
executed_at_column_name: null
execution_time_column_name: null
migrations: {  }
connection: null
em: null
all_or_nothing: false
check_database_platform: true
custom_template: null
organize_migrations: false

检查迁移脚本的名称空间和迁移包的配置。将目录从src/migrations移动到migrations后,必须将文件的名称空间更改为DoctrineMigrations,并将存储表名称更改为存在的名称空间(否则,新的默认迁移表名称为doctrine_migration_versions(。

以下是我的建议:/migrations 中的一些迁移文件

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use DoctrineDBALSchemaSchema;
use DoctrineMigrationsAbstractMigration;
// ...

配置:

doctrine_migrations:
migrations_paths:
# namespace is arbitrary but should be different from AppMigrations
# as migrations classes should NOT be autoloaded
'DoctrineMigrations': '%kernel.project_dir%/migrations'
storage:
# Default (SQL table) metadata storage configuration
table_storage:
table_name: 'migration_versions'

这有助于我使用Symfony5从头开始设置项目,并与当前运行的生产系统向后兼容。

我认为您需要在"php bin/console make:migration:migrate"之前运行命令"php bin/console make:migration"

我希望这会有所帮助。

最新更新