Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations will raise an exception if there are multiple column defin… #33029

merged 1 commit into from Jun 4, 2018


Copy link

@fedxgibson fedxgibson commented May 31, 2018

Migrations raise exception when defining already defined column.

TableDefinition#column checks if there is already a column defined with the same name. In this case it will raise an exception.

Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@fedxgibson fedxgibson force-pushed the raise_with_duplicate_columns branch from 7dd704c to 7ef9849 Compare June 1, 2018 21:59
@eileencodes eileencodes merged commit c4c8e35 into rails:master Jun 4, 2018
Copy link

Thanks for fixing this! 🎉

Copy link
Contributor Author

Glad to help! :)

NickLaMuro added a commit to NickLaMuro/manageiq-schema that referenced this pull request Dec 11, 2020
In Rails 6, a "bug fix" was added to avoid creating duplicate columns:


This wasn't very well described what this was fixing, but this seems to
be the issue it was fixing:


However, the problem we had as a result was this error with our specs
when running migrations:

  1) ExpandDialogFieldDefaultValueSize#down with empty tables
     Failure/Error: super

       An error has occurred, this and all later migrations canceled:

       you can't define an already defined column 'miq_server_id'.
     # ./db/migrate/20160328204930_remove_miq_server_product_update_join_table.rb:21:in `block in down'
     # ./db/migrate/20160328204930_remove_miq_server_product_update_join_table.rb:20:in `down'
     # ./lib/manageiq/schema/migrate_with_cleared_schema_cache.rb:6:in `block in migrate'
     # ./lib/manageiq/schema/migrate_with_cleared_schema_cache.rb:18:in `clearing_caches'
     # ./lib/manageiq/schema/migrate_with_cleared_schema_cache.rb:5:in `migrate'
     # ./spec/support/migration_helper.rb:109:in `block in migrate_to'
     # ./spec/support/migration_helper.rb:99:in `suppress_migration_messages'
     # ./spec/support/migration_helper.rb:105:in `migrate_to'
     # ./spec/support/migration_helper.rb:42:in `prepare_migrate'
     # ./spec/support/migration_helper.rb:8:in `block (2 levels) in migration_context'
     # ------------------
     # --- Caused by: ---
     # ArgumentError:
     #   you can't define an already defined column 'miq_server_id'.
     #   ./db/migrate/20160328204930_remove_miq_server_product_update_join_table.rb:21:in `block in down'

And was expressed by this issue to rails:


In which the answer was "fix your migrations".

I don't really buy that answer, as that is why they have versioned
migration classes in the first place, but for now, this is the fix
available to us and seems to allow most of the specs to pass.

On top of that, we can't use `create_join_table` as we previously did
since we now can't overwrite default columns and choose what column
type we want to use since the only thing we can provide with the kwargs
is the `:column_options`, but we will always get the foriegn_key columns
as `integer`.

That said, this is a down migration, so probably not worth investing
trying to get this changed upstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

5 participants