Doctrine – 回滚所有迁移

huangapple go评论84阅读模式
英文:

Doctrine - Rollback all migrations

问题

我似乎在Symfony和Doctrine中遇到了一个有些奇怪的问题,其中有许多可用的迁移积压,其中许多是重复的,有些旨在执行不再存在的表的查询。

我希望只需回滚或“删除”所有这些可用的迁移,以便我可以在新数据库上运行迁移,并且一切都与我的代码中一样。

以下是一个示例(这只是一个干跑):

++ 迁移 20200103023439

  • 创建表user(id INT AUTO_INCREMENT NOT NULL,username VARCHAR(180) NOT NULL,username_canonical VARCHAR(180) NOT NULL,email VARCHAR(180) NOT NULL,email_canonical VARCHAR(180) NOT NULL,enabled
    TINYINT(1) NOT NULL,salt VARCHAR(255) DEFAULT NULL,password VARCHAR(255) NOT NULL,last_login DATETIME DEFAULT NULL,confirmation_token VARCHAR(180) DEFAULT NULL,password_requested_at DATETIME DEFAULT NULL,
    roles LONGTEXT NOT NULL COMMENT ‘(DC2Type:array)’,name VARCHAR(255) NOT NULL,UNIQUE INDEX UNIQ_8D93D64992FC23A8 (username_canonical),UNIQUE INDEX UNIQ_8D93D649A0D96FBF (email_canonical),UNIQUE INDEX UNIQ_8
    D93D649C05FB297 (confirmation_token),PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 entry(id INT AUTO_INCREMENT NOT NULL,album VARCHAR(255) NOT NULL,artist VARCHAR(255) NOT NULL,tracklist LONGTEXT NOT NULL COMMENT ‘(DC2Type:array)’,review LONGTEXT NOT NULL,image VARC
    HAR(255) NOT NULL,timestamp DATETIME NOT NULL,author VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 tag(id INT AUTO_INCREMENT NOT NULL,name VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 task(id INT AUTO_INCREMENT NOT NULL,description VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 track(id INT AUTO_INCREMENT NOT NULL,name VARCHAR(255) DEFAULT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

++ 迁移成功(0秒)

++ 迁移 20200103023541

  • 创建表 entry(id INT AUTO_INCREMENT NOT NULL,album VARCHAR(255) NOT NULL,artist VARCHAR(255) NOT NULL,tracklist LONGTEXT NOT NULL COMMENT ‘(DC2Type:array)’,review LONGTEXT NOT NULL,image VARC
    HAR(255) NOT NULL,timestamp DATETIME NOT NULL,author VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 tag(id INT AUTO_INCREMENT NOT NULL,name VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 task(id INT AUTO_INCREMENT NOT NULL,description VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 track(id INT AUTO_INCREMENT NOT NULL,name VARCHAR(255) DEFAULT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

++ 迁移成功(0秒)

++ 迁移 20200103023707

  • 创建表 entry(id INT AUTO_INCREMENT NOT NULL,album VARCHAR(255) NOT NULL,artist VARCHAR(255) NOT NULL,tracklist LONGTEXT NOT NULL COMMENT ‘(DC2Type:array)’,review LONGTEXT NOT NULL,image VARC
    HAR(255) NOT NULL,timestamp DATETIME NOT NULL,author VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 tag(id INT AUTO_INCREMENT NOT NULL,name VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 task(id INT AUTO_INCREMENT NOT NULL,description VARCHAR(255) NOT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  • 创建表 track(id INT AUTO_INCREMENT NOT NULL,name VARCHAR(255) DEFAULT NULL,PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

++ 迁移成功(0秒)

您可以看到它试图多次创建多个表,实际运行此迁移时,当然会导致许多错误。

我一直在尝试将其中一些版本迁移到下面,但即使这些版本也会导致SQLSTATE错误:

php bin/console doctrine:migrations:execute 20200102235626 --down

非常感谢您的帮助,我已经思考了几个小时。

英文:

I seem to be having a bit of an odd problem with Symfony and Doctrine wherein a have a buildup of available migrations, many of which are duplicates and some aiming to perform queries of tables that no longer exist.

I'm looking to just rollback or 'remove' all of these available migrations so that I can just run a migration on a new database and everything will be how it is in my code.

Below is an example (this is just a dry-run):

  ++ migrating 20200103023439

     -> CREATE TABLE `user` (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(180) NOT NULL, username_canonical VARCHAR(180) NOT NULL, email VARCHAR(180) NOT NULL, email_canonical VARCHAR(180) NOT NULL, enabled
 TINYINT(1) NOT NULL, salt VARCHAR(255) DEFAULT NULL, password VARCHAR(255) NOT NULL, last_login DATETIME DEFAULT NULL, confirmation_token VARCHAR(180) DEFAULT NULL, password_requested_at DATETIME DEFAULT NULL,
 roles LONGTEXT NOT NULL COMMENT '(DC2Type:array)', name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D64992FC23A8 (username_canonical), UNIQUE INDEX UNIQ_8D93D649A0D96FBF (email_canonical), UNIQUE INDEX UNIQ_8
D93D649C05FB297 (confirmation_token), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE entry (id INT AUTO_INCREMENT NOT NULL, album VARCHAR(255) NOT NULL, artist VARCHAR(255) NOT NULL, tracklist LONGTEXT NOT NULL COMMENT '(DC2Type:array)', review LONGTEXT NOT NULL, image VARC
HAR(255) NOT NULL, timestamp DATETIME NOT NULL, author VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE task (id INT AUTO_INCREMENT NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE track (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  ++ migrated (0s)

  ++ migrating 20200103023541

     -> CREATE TABLE entry (id INT AUTO_INCREMENT NOT NULL, album VARCHAR(255) NOT NULL, artist VARCHAR(255) NOT NULL, tracklist LONGTEXT NOT NULL COMMENT '(DC2Type:array)', review LONGTEXT NOT NULL, image VARC
HAR(255) NOT NULL, timestamp DATETIME NOT NULL, author VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE task (id INT AUTO_INCREMENT NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE track (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  ++ migrated (0s)

  ++ migrating 20200103023707

     -> CREATE TABLE entry (id INT AUTO_INCREMENT NOT NULL, album VARCHAR(255) NOT NULL, artist VARCHAR(255) NOT NULL, tracklist LONGTEXT NOT NULL COMMENT '(DC2Type:array)', review LONGTEXT NOT NULL, image VARC
HAR(255) NOT NULL, timestamp DATETIME NOT NULL, author VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE task (id INT AUTO_INCREMENT NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
     -> CREATE TABLE track (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

  ++ migrated (0s)

You can see that it is trying to create several tables multiple times, when actually running this migration this, of course, results in many errors.

I have been trying to migrate some of these versions down, but even these result in SQLSTATE errors:

php bin/console doctrine:migrations:execute 20200102235626 --down

Any help would be greatly appreciated, I have been wrapping my head around this for hours.

答案1

得分: 1

啊,我真傻!我不知道我可以简单地删除DoctrineMigrations文件夹中的所有迁移PHP文件。

英文:

Ah, silly me! Unbeknownst to me I could simply delete all of the migration PHP files within the DoctrineMigrations folder.

huangapple
  • 本文由 发表于 2020年1月4日 01:31:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582862.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定