Reputation: 11
In my endless stupidness I changed the mysql db using mysql and not migrations, so now the db is out of sync with migration.
my question is, if it's possible to generate the missing migrations (step) and a new schema.db without loosing data and the changes* in the db?
*changes like adding tables, columns.
thx
Upvotes: 1
Views: 102
Reputation: 22268
As far as recreating your migrations, you're out of luck but you can recreate the schema
rake db:schema:dump
If you go this route, when creating a new db (for a new environment etc...) you'll want to do
RAILS_ENV=some_env rake db:schema:load # specify the env if not development
instead of
rake db:migrate
since your migrations do not align with the current schema.
Be careful when running schema:load
as it recreates the db from scratch. i.e. you'll lose all data.
Upvotes: 1
Reputation: 23344
It will be good to create the missing migrations. You can fix your local dev database by adding the timestamps to the schema_migrations
table manually. That is the consequence of changing your schema by hand.
Also make sure that rake db:migrate:reset
(drop all tables and migrate from scratch) will produce the same db/schema.rb
as rake db:schema:dump
would. Any change in the database schema must be automated by a migration.
The problem with rake db:schema:load
is that it will forcefully create the tables.
Upvotes: 0