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

Expand the caveat about models in migrations in the rails guide. #7050

Merged
merged 1 commit into from
Oct 11, 2012
Merged

Expand the caveat about models in migrations in the rails guide. #7050

merged 1 commit into from
Oct 11, 2012

Conversation

kytrinyx
Copy link
Contributor

This is an attempt to address issue #6939, where an earlier migration
added a column to the database, and a later migration uses a model and
references that column.

When both migrations were run together with rake db:migrate the column
information in memory still referenced the old table structure.

Running the migrations separately fixed this, as a new connection was
then established before referencing the model. Explicitly calling
reset_column_information is a more reliable workaround.

@kytrinyx
Copy link
Contributor Author

I'm not sure if this documentation change is enough to address the issue in #6939. Do you think it would be helpful to be more explicit?

@dmathieu
Copy link
Contributor

This is not informative enough. It might make people think there is some latency for new database fields to be considered, when it's only a simple in memory cache.
You could also mention the use of reset_column_information.

@kytrinyx
Copy link
Contributor Author

Good point. Ok, I've tried to expand it at the bottom of the existing section. I initially went overboard with code examples, but I think that it's not important enough to warrant a huge section for itself, I just want to make the point that using models is iffy and can lead to subtle and complicated problems, and that this should be handled with care.

I'd be happy to tweak further if you have any good ideas.

@rafaelfranca
Copy link
Member

cc @fxn @vijaydev

@vijaydev
Copy link
Member

I feel this is a bit too verbose, but I'm ok to merge. Please either rebase & squash the commits into one, Or make these changes in docrails. Thanks.

This is an attempt to address issue #6939, where an earlier migration
added a column to the database, and a later migration uses a model and
references that column.

When both migrations were run together with `rake db:migrate` the column
information in memory still referenced the old table structure.

Running the migrations separately fixed this, as a new connection was
then established before referencing the model. Explicitly calling
`reset_column_information` is a more reliable workaround.
@kytrinyx
Copy link
Contributor Author

Thank you. I've rebased and squashed the commits.

vijaydev added a commit that referenced this pull request Oct 11, 2012
Expand the caveat about models in migrations in the rails guide.
@vijaydev vijaydev merged commit cd98c25 into rails:master Oct 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants