Migration exception: alter table --> Column already exists: 1060 Duplicate column name

2.5k Views Asked by At

After doing php flow flow:doctrine:migrate... I got following error:

An exception occurred while executing 'ALTER TABLE user ADD gdisplayname LONGTEXT DEFAULT NULL, ADD tdisplayname LONGTEXT DEFAULT NULL, ADD fdisplayname LONGTEXT DEFAULT NULL': SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'gdisplayname'

I tried to remove the already existing column using:

ALTER TABLE user DROP COLUMN gdisplayname;

and then reusing php flow flow:doctrine:migrate

It does not work. How can I remove this errors without the need to dump the whole database and to successfully migrate the database?

Thanks in advance.

2

There are 2 best solutions below

0
lorenz On BEST ANSWER

If a migration is already applied, you can set it as migrated so Flow won't try to apply it again. First, check which migration is causing the error

./flow doctrine:migrationstatus

Then set it as migrated:

./flow:doctrine:migrationversion --version <version> --add
0
Biggles-2 On

Just tried @lorenz answer and there's a minor difference in syntax if you're using Symfony console for both commands.

To check migrations status:

php bin/console doctrine:migrations:status 

To set as migrated:

 php bin/console doctrine:migrations:version 'DoctrineMigrations\<version>' --add