Reputation: 8631
Every time I commit code that has a migration, for some reason, I get a bunch of schema changes that I didn't write, that came from previous PRs.
For example, i'll write a migration to add a column on User...but after running the migration, the schema file will include 10 changes from previous old code that isn't in the current branch at all.
How do I fix this?
Upvotes: 1
Views: 766
Reputation: 1228
The schema file reflect to the database schema. I think you had changed the schema at previous old code but didn't recover(rollback) it, deleted it and start coding for new migration.
The thing you shloud do is eliminating diff between code and datebase.
Solution:
Checkout to your old branch and rollback the schema change by runningrake db:migrate:down VERSION=20161106xxxxxx
.
or
rake db:rollback STEP=n
rollback schema change done by current branchrake db:rollback STEP=m
to rollback schema change by old branch.rake db:migrate
, and you will not see the extra changes in schema file.reference:
Upvotes: 2
Reputation: 1
There are two possibilities:
You haven't deleted the code for the previous migrations that you are trying to neglect from the schema.rb file.
You're very new to rails and you tried deleting fields from the schema.rb file manually, thinking it would synchronize with your database.
Either way: delete all the migration files you don't want if you haven't already, then simply rollback your database to the original empty version using the command:
rake db:rollback VERSION=0
Then: Now that you have the right migration files, migrate to your databse using the command:
rake db:migrate
This should give you an accurate schema.rb file
Upvotes: 0