Heroku rake db: migrate

Geroku tells me that there are migrations that weren't triggered when they obviously were. It looks like this is behind one migration. How can I solve this problem.

When I run it rake db:migrate

, it tells me rake aborted Mysql2::Error: Duplicate column name

. I know that these fields have already been created, and I am also confident that the migration is done as these fields do not exist in any other migration and rake db: migrate works very well on my local system.

How can I fix this? I think Heroku just didn't realize that it had already led to migration. How can I say that "you have already migrated xxx"?

+3


source to share


2 answers


This probably means that you ran it once, but it failed; table variables in mysql are not transactional, so you might leave them in a bad state. Some of these changes may have been implemented, but not all of them.



The only thing you can do is determine which parts were already running, comment out that line in the migration, commit and push and run the migration bypassing the parts that were already running.

+4


source


If the migration is not fully applied, do one of the following:

  • Use dbconsole to revert the changes that were applied and then migrate again, or
  • manually change the rest of the schema changes using dbconsole and then insert the record into the table schema_migrations

    .

Depending on what types of changes are in the migration script, you need to decide which of the above questions is easiest. If the changes already made are destructive changes, such as dropping a column or table, you can recreate the column or table so the migration can work. If the rest of the changes are easy to translate to SQL, it might be easier.



Inserting a record into the table schema_migrations

will let the application think that the migration has been successfully applied. Only do this if you are absolutely certain that the migration changes have been fully applied. It has one column, version

which must contain the numeric part of the migration file name.

http://api.rubyonrails.org/classes/ActiveRecord/Migration.html http://guides.rubyonrails.org/migrations.html

Finally, this is an example of why you should use Postgres instead of MySQL. Postgres can rollback (most) schema changes in a transaction, so you don't end up with a half-application migration.

+1


source







All Articles