0
votes

After I had a bug in php my admin I deleted all the tables from it to solve it.

Now I want to rebuild my database using doctrine migrations (but not the very last migration as it is the one which caused the bug).

How can I make a migration at an previous state?

Edit : by doing the migrate command it recreates my table however everytime I try a new

php bin/console doctrine:migrations:migrate

I get the following error messages :

[notice] Migrating up to DoctrineMigrations\Version20201124181841 [error] Migration DoctrineMigrations\Version20201124174448 failed during Execution. Error: "An exception occurred while executing 'CREATE TABLE publishers (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, contact_firstname VARCHAR(255) NOT NULL, contact_lastname VARCHAR(255) NOT NULL, contact_email VARCHAR(255) NOT NULL, contact_phonecode VARCHAR(255) NOT NULL, contact_phone VARCHAR(255) NOT NULL, public_phonecode VARCHAR(255) DEFAULT NULL, public_phone VARCHAR(255) DEFAULT NULL, public_email VARCHAR(255) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, logo VARCHAR(255) DEFAULT NULL, facebook VARCHAR(255) DEFAULT NULL, twitter VARCHAR(255) DEFAULT NULL, instagram VARCHAR(255) DEFAULT NULL, address VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, zip VARCHAR(255) DEFAULT NULL, country VARCHAR(255) NOT NULL, company_number VARCHAR(255) NOT NULL, registration_date DATETIME NOT NULL, modification_date DATETIME DEFAULT NULL, description LONGTEXT DEFAULT NULL, tagline VARCHAR(255) DEFAULT NULL, slug VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':

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

In AbstractMySQLDriver.php line 57:

An exception occurred while executing 'CREATE TABLE publishers (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) N OT NULL, contact_firstname VARCHAR(255) NOT NULL, contact_lastname VARCHAR(255) NOT NULL, contact_email VARCHAR(255 ) NOT NULL, contact_phonecode VARCHAR(255) NOT NULL, contact_phone VARCHAR(255) NOT NULL, public_phonecode VARCHAR( 255) DEFAULT NULL, public_phone VARCHAR(255) DEFAULT NULL, public_email VARCHAR(255) DEFAULT NULL, website VARCHAR( 255) DEFAULT NULL, logo VARCHAR(255) DEFAULT NULL, facebook VARCHAR(255) DEFAULT NULL, twitter VARCHAR(255) DEFAULT
NULL, instagram VARCHAR(255) DEFAULT NULL, address VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, zip VARCHAR(255) DEFAULT NULL, country VARCHAR(255) NOT NULL, company_number VARCHAR(255) NOT NULL, registration_date D ATETIME NOT NULL, modification_date DATETIME DEFAULT NULL, description LONGTEXT DEFAULT NULL, tagline VARCHAR(255) DEFAULT NULL, slug VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_c i ENGINE = InnoDB':

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

In Exception.php line 18:

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

In PDOConnection.php line 52:

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

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--configuration CONFIGURATION] [--db-configuration DB-CONFIGURATION] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] []

How can I fix this?

1

1 Answers

0
votes

You can migrate to a chosen migration number, say there are 10 migrations and you want to migrate all except 10

bin/console doctrine:migrations:migrate 9

where 9 should be replaced with migration timestamp, for instance 20201124100000

Or, you could backup last migration in case you need it, delete the original so there's only 9 left in the folder and run

bin/console doctrine:migrations:migrate

Or, you can execute them one by one, just keep count not to execute the last one

bin/console doctrine:migrations:migrate first-migration-timestamp
bin/console doctrine:migrations:migrate next