简体   繁体   English

如何将“ schema.rb”重置为最后的git head?

[英]How to reset 'schema.rb' to last git head?

I want to get rid of everything I did since my last commit, including the tables I created, so I did 我想摆脱上一次提交以来所做的一切,包括我创建的表,所以我做了

git reset --hard HEAD
git clean -f -d

so this got rid of the migrations I created, but in the schema it looks like the tables are still there. 所以这摆脱了我创建的迁移,但是在模式中,看起来表格仍然存在。 I know I can just create new migrations to drop those tables, but I was just wondering for future references how I could reset to the last commit even on the database level. 我知道我可以创建新的迁移来删除这些表,但是我只是想知道将来的参考资料,即使在数据库级别也如何可以重置为上一次提交。

Another reason why I would need to delete the tables in the database is because when I try to create migrations(models) to create the exact tables, it gives me an error and says they already exist. 我需要删除数据库中表的另一个原因是,当我尝试创建迁移(模型)以创建精确表时,它给了我一个错误,并说它们已经存在。 So if I were to push this to github and production, it would not create the tables since the migrations don't exist. 因此,如果我将其推送到github和production,由于迁移不存在,它将不会创建表。 Thus, I think it is necessary for me to delete the created tables locally through some sort (preferably rolling back), and then re-create the migrations. 因此,我认为有必要通过某种方式(最好是回滚)在本地删除创建的表,然后重新创建迁移。

(I'm using PostGreSQl) (我正在使用PostGreSQl)

So I solved this temporarily, but probably not the most ideal way to do it.. I just created migrations to remove the tables, ran rake db:migrate, and then deleted the migrations. 因此,我暂时解决了这个问题,但可能不是最理想的解决方法。.我只是创建了迁移以删除表,运行rake db:migrate,然后删除了迁移。 So this way it's like it never happened. 因此,这就像从未发生过。

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

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