4
votes

After creating an Entity and Repository from an existing pre-doctrine database, I am unable to make an initial migration. It gave me this error [ERROR] The version "latest" couldn't be reached, there are no registered migrations. Any idea how to do an initial migration without starting fresh? And for some reason, the migration folder exists outside the src folder, why is it so? In a previous project, the migration folder exists inside the src folder.

Any insight would be appreciated. Thank you for reading.

EDIT: doctrine_migrations.yaml:

doctrine_migrations:
    migrations_paths:
        # namespace is arbitrary but should be different from App\Migrations
        # as migrations classes should NOT be autoloaded
        'DoctrineMigrations': '%kernel.project_dir%/migrations'

The commands I used to generate the Entity and its Repository is as follows:

  1. php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
  2. modified the @ORM\Entity => @ORM\Entity(repositoryClass="App\Repository\UserRepository") in the entity .php
  3. php bin/console make:entity --regenerate

Then when I run bin/console doctrine:migrations:migrate, the error pops up.

3
Could you show your config files for doctrine_migrations (and maker if using) and the commands you are using?DasBen
This error shows if the script can't find any migrations files in the specified folder. Check your config path and make sure you use the right config with the right migrations bundle version: symfony.com/doc/master/bundles/DoctrineMigrationsBundle/…Jeroen
@DasBen updated with doctrine_migration.yaml, I understand why migration folder is outside.cswannabe
@Jeroen, I am able to generate an initial migration using doctrine:migrations:dump-schema. However, changes to the entity are not detected.cswannabe

3 Answers

2
votes

Work for me

doctrine_migrations:
    migrations_paths:
        'App\Migrations': '%kernel.project_dir%/src/Migrations'

and use for migration classes

namespace App\Migrations;
0
votes

THis is my migrations config.You can test it :

doctrine_migrations:
    dir_name: '%kernel.project_dir%/src/Migrations'
    # namespace is arbitrary but should be different from App\Migrations
    # as migrations classes should NOT be autoloaded
    namespace: DoctrineMigrations

For migration commande i use : php bin/console d:m:diff and after this you can use the migration number with this commande : php bin/console d:m:e --up the_migration_number

0
votes

I tried most of the methods but it seems that it is possible to generate the migration. However, changes to the entity will not be detected by doctrine.

For example, if I change the field of name to username, php bin/console doctrine:migration:diff does not detect the changes.

What I found worked was exporting the database as .sql, creating the entity the normal way, and manually typing in the fields. Delete the generated table in phpmyadmin, and importing the data back in. Only then would it be working as I want it to be.