0

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.

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.

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

sixty4bit
  • 7,422
  • 7
  • 33
  • 57
  • Looking forward to feedback from the person who down-voted as to why this is a bad question. Thanks in advance! – sixty4bit Dec 12 '14 at 16:49
  • I personally found it useful and did research it without any luck. I guess I must not have used the right search terms. If the question is unclear and/or not useful, should I just delete it? Please try to recall the time when you didn't have 92k rep. I'm trying my best here. – sixty4bit Dec 12 '14 at 16:52
  • what do you mean `I'm still seeing discount_code_id as an attribute.`? how did you see it? – Малъ Скрылевъ Dec 12 '14 at 16:56
  • @МалъСкрылевъ I typed the capitalized name of the model in the console which returned a list of all the attributes – sixty4bit Dec 12 '14 at 16:57
  • 1
    @sixty4bit meagar is correct, you have migrated your db before change to master, and after the db structure stays the same. So you have to reconstruct db: like the follows: http://stackoverflow.com/questions/19097558/pg-undefinedtable-error-relation-users-does-not-exist/19804714#19804714 – Малъ Скрылевъ Dec 12 '14 at 17:01

1 Answers1

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.

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.

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.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • Thanks, I have 2 minutes before I can accept an answer. Can you explain what you mean when you say that migrations don't directly influence my models at all? I have been writing migrations in order to change my models. I'm guessing that I'm just conflating terms somehow. I realize that the database table isn't the model, so is it right to say that the migrations affect the table and the model describes how the table can be interacted with? – sixty4bit Dec 12 '14 at 16:59