Rails 3.2 / Git:当我切换回master时,为什么我的模型仍然有来自功能分支的attr?

时间:2022-11-24 09:27:23

In my discount_codes branch I created a migration that adds a discount_code_id attribute to the Job model. When I switch back to the master branch, open a console, and type Job, I'm still seeing discount_code_id as an attribute.

在我的discount_codes分支中,我创建了一个迁移,它将discount_code_id属性添加到Job模型中。当我切换回主分支,打开一个控制台,然后输入Job时,我仍然将discount_code_id视为一个属性。

Because I'm back on the master branch, the migrations that added this attribute aren't there and schema.rb doesn't list it as a column in the Job table.

因为我回到主分支,所以添加此属性的迁移不存在,schema.rb不会将其列为Job表中的列。

Can someone explain why I'm still seeing the new attribute in the console?? This happens despite opening a new console.

有人可以解释为什么我仍然在控制台中看到新属性?尽管打开了新的控制台,但仍会发生

1 个解决方案

#1


3  

Your actual database isn't controlled by Git, and changing branches doesn't affect the database in any way. The column will be there unless you manually run the down migration before changing branches, or remove it manually.

您的实际数据库不受Git控制,更改分支不会以任何方式影响数据库。除非您在更改分支之前手动运行向下迁移,否则该列将在那里,或手动删除它。

Neither schema.rb or the migrations are responsible for giving fields to your models; the model's fields are defined by the actual state of the database, and as I said, that isn't changed by switching branches.

schema.rb或迁移都不负责为模型提供字段;模型的字段由数据库的实际状态定义,正如我所说,切换分支不会改变。

All that migrations and schema.rb are for are restoring/moving the state of your database. They don't directly influence your models at all.

所有迁移和schema.rb都用于恢复/移动数据库的状态。它们根本不会直接影响您的模型。

#1


3  

Your actual database isn't controlled by Git, and changing branches doesn't affect the database in any way. The column will be there unless you manually run the down migration before changing branches, or remove it manually.

您的实际数据库不受Git控制,更改分支不会以任何方式影响数据库。除非您在更改分支之前手动运行向下迁移,否则该列将在那里,或手动删除它。

Neither schema.rb or the migrations are responsible for giving fields to your models; the model's fields are defined by the actual state of the database, and as I said, that isn't changed by switching branches.

schema.rb或迁移都不负责为模型提供字段;模型的字段由数据库的实际状态定义,正如我所说,切换分支不会改变。

All that migrations and schema.rb are for are restoring/moving the state of your database. They don't directly influence your models at all.

所有迁移和schema.rb都用于恢复/移动数据库的状态。它们根本不会直接影响您的模型。