I have a branch that has a different schema than my master. When I try to rebase with master, I get a merge conflict error with the schemas. I understand that this is happening because my schema on my branch is different than the one on my master. This is because I was working on something else in another branch and had to run migrations. I then merged that branch with my master. So now my master has a new table in the schema which the branch I am working on has no idea. So when I try to rebase with master it gives me a conflict error. Is there a way for the branch to automatically merge and take up the latest schema from the master when I rebase? I know there is a code snippet which I can put in my config file and call it in my attributes file, however, this solution does not seem to work for me since my migrations were made before I put that code in the config file.
3 Answers
If schema.rb
(or any file for that matter) changed since you created your branch then you would have to manually merge the conflict.
Conflict happens only when file from both the branches have new changes present around same line numbers.
Doing below like mentioned in another answer would make you lose the changes done in your current branch:
git rebase -Xtheirs the_branch_name
In case of schema.rb
generally the version number line throws the conflict. You should always put the higher number of two versions:
ActiveRecord::Schema.define(version: 2017081234567)

- 1,643
- 12
- 17
-
It is correct : using `theirs` and `ours` is not intuitive when rebasing (`theirs` is actually the branch you're working on and `ours` the master branch) – Pak Nov 14 '18 at 12:45
Delete the schema file, apply migrations if there are any at this stade of the rebase, dump the new rails schema and git rebase --continue
. Repeat when necessary.

- 2,123
- 22
- 28
Since schema.rb is automatically generated after each migration, the simplest way to resolve conflict is to remove this file, run
rake db:drop db:create db:migrate
and commit the changes.

- 1,128
- 8
- 14
-
No need to drop your database everytime you're doing this. What about multi-gigabytes dev DB ? – Pak Nov 14 '18 at 11:32
-
@Pak do it agains test db: `RAILS_ENV=test rake db:drop db:create db:migrate` – Tema Bolshakov Nov 15 '18 at 12:03