简体   繁体   English

从不同的git分支上的mysql数据库恢复已删除的列

[英]restore deleted column from mysql db on different git branch

In my test branch, I ran a rails migration to remove a column from one of my database tables. 在测试分支中,我进行了Rails迁移,以从我的一个数据库表中删除一列。 The migration ran successfully and the column was deleted. 迁移成功运行,该列已删除。 But then I created another fresh branch from master in which I needed that column and checked-out onto it. 但是后来我从master创建了另一个新分支,在该分支中我需要该列并签出。 The column was still deleted, but my model had the attribute, and also there is no migration in this branch that I can rollback to get the column back. 该列仍被删除,但是我的模型具有该属性,并且该分支中没有迁移,因此我可以回滚以将该列取回。

You have to reset the db migrations. 您必须重置数据库迁移。 Run this command in cmd to reset the migrations: 在cmd中运行以下命令以重置迁移:

rake db:migrate:reset

It'll reset your database depends on your current branch's migration. 它将根据当前分支的迁移来重置数据库。 If you move to your previous branch where you delete your column you've to run the command again to apply the changes. 如果移至删除分支的上一个分支,则必须再次运行命令以应用更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM