运行Ruby on Rails迁移,schema.rb已更新,但更改未反映在psql数据库中

时间:2022-05-02 23:21:41

I have a ruby on rails application already running in production. The database has records which I do not want to loose. I had to add and run new migrations to add some new columns to existing tables. The migrations run successfully and the schema.rb file reflects the changes but the changes do not appear in the database or existing table structure.

我有一个ruby on rails应用程序已经在生产中运行。数据库有我不想放弃的记录。我不得不添加并运行新的迁移,以向现有表添加一些新列。迁移成功运行,schema.rb文件反映了更改,但更改未显示在数据库或现有表结构中。

Based on research online, rake db:schema:load updates the db based on the schema.rb file. But this resets the database.

基于在线研究,rake db:schema:load基于schema.rb文件更新db。但这会重置数据库。

It is crucial that I do not loose the data in the tables.Is there any way to solve this? I am fairly new to ruby on rails.

至关重要的是我不要丢失表中的数据。有什么方法可以解决这个问题吗?我对铁轨上的红宝石相当新。

1 个解决方案

#1


1  

I was able to fix it. I checked the status of migrations in the production environment rake db:migrate:status RAILS_ENV=production and realised they were down. I then run rake db:migrate RAILS_ENV=production and that did it. Changes now reflect in the db. Thanks @muistooshort for the nudge in the right direction

我能够解决它。我检查了生产环境中的迁移状态rake db:migrate:status RAILS_ENV = production并意识到它们已关闭。然后我运行rake db:migrate RAILS_ENV = production并且这样做了。现在的变化反映在db中。感谢@muistooshort在正确的方向上轻推

#1


1  

I was able to fix it. I checked the status of migrations in the production environment rake db:migrate:status RAILS_ENV=production and realised they were down. I then run rake db:migrate RAILS_ENV=production and that did it. Changes now reflect in the db. Thanks @muistooshort for the nudge in the right direction

我能够解决它。我检查了生产环境中的迁移状态rake db:migrate:status RAILS_ENV = production并意识到它们已关闭。然后我运行rake db:migrate RAILS_ENV = production并且这样做了。现在的变化反映在db中。感谢@muistooshort在正确的方向上轻推