Symfony: Base table or view already exists: 1050 Table 'migration_versions' already exists

寵の児 提交于 2021-02-10 05:15:31

问题


I've done something horribly wrong to my migration_versions, deleted the versions from the migrations folder now and I get this error when try to run anything to do with migrations. Could someone point me in the direction of where to start to fix this?

If I drop the database and then make:migration, the migration_versions table appears in the db. After that if I try to run

php bin/console doctrine:migrations:migrate

I get the error:

In AbstractMySQLDriver.php line 38:

  An exception occurred while executing 'CREATE TABLE migration_versions (version VARCHAR(14) NOT NULL, executed_at   
  DATETIME NOT NULL COMMENT '(DC2Type:datetime_immutable)', PRIMARY KEY(version)) DEFAULT CHARACTER SET utf8mb4 COLL  
  ATE `utf8mb4_unicode_ci` ENGINE = InnoDB':                                                                          

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'migration_versions' already exists                  


In PDOConnection.php line 43:

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'migration_versions' already exists  


In PDOConnection.php line 41:

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'migration_versions' already exists  

If I then drop that table from the db I can then run the php bin\console doctrine:migrations:migrate fine. But when attempting to run any further make:migration/doctrine:migrations:migrate commands I get the same error as previous stating that the table migration_versions exists.


回答1:


The same problem happened to me because of a schema_filter in my config. My doctrine.yaml file (Symfony 4) had the following:

doctrine:
    dbal:
        schema_filter: ~^(table_1|table_2|table_3)$~

I had to simply add "migration_versions" to the schema filter like so:

doctrine:
    dbal:
        schema_filter: ~^(migration_versions|table_1|table_2|table_3)$~



回答2:


I had a similar issue, where I only wanted to change a field name.

The same problem happend after changing the fieldname and try to migrate that with the two commands.

I fixed it with:

  • I removed the database content and the migrations/Versionfiles.
  • Did bin/console make:migration
  • And bin/console doctrine:migrations:migrate

and it worked again.



来源:https://stackoverflow.com/questions/61262556/symfony-base-table-or-view-already-exists-1050-table-migration-versions-alre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!