Ruby on Rails
Thursday, March 28, 2019
Thanks for the links - that clears it up.
-- The reason for using a migration and not seed data, is that this is real data needed in our production db, and I use seeds.rb to populate my development db with data to test with.
onsdag den 27. marts 2019 kl. 22.33.42 UTC+1 skrev Eito Katagiri:
onsdag den 27. marts 2019 kl. 22.33.42 UTC+1 skrev Eito Katagiri:
You need to call .reset_column_information in third migration. Please referhttps://api.rubyonrails.org/classes/ActiveRecord/ for details.ModelSchema/ClassMethods.html# method-i-reset_column_ information You can insert and update data in migration, but you might want to consider using db/seeds.rb instead.HTH2019年3月27日(水) 23:36 <t...@stinto.com>:I'm running Rails 5.0.6, and I can't Google myself to any other occurences of this problem.The migrations fail when I have a migration that inserts data into a table, that has data for a column that was added in a previous migration file executed by the same migrate commandBasically I have 3 migrations that are run with the following command
rails db:migratefirst migration chronologically:
create_table :campaign_orders do |t|
t.integer :order
endsecond migration:
add_column :campaign_orders, :priority, :integerthird migration:
CampaignOrder.create(order: 0, priority: 1)The third migration fails, if all migrations are outstanding when running migrate command, but succeeds if you run the migrate command again. It fails with the following error:rails aborted!
StandardError: An error has occurred, all later migrations canceled:
unknown attribute 'priority' for CampaignOrder.
/Users/tomwilliams/Projects/incard-rails/db/migrate/ 20190326143614_insert_ accepted_email_campaign.rb:66: in `up'
/Users/tomwilliams/Projects/incard-rails/bin/rails:9:in `require'
/Users/tomwilliams/Projects/incard-rails/bin/rails:9:in `<top (required)>'
/Users/tomwilliams/Projects/incard-rails/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Caused by:
ActiveModel::UnknownAttributeError: unknown attribute 'priority' for CampaignOrder.
/Users/tomwilliams/Projects/incard-rails/db/migrate/ 20190326143614_insert_ accepted_email_campaign.rb:66: in `up'
/Users/tomwilliams/Projects/incard-rails/bin/rails:9:in `require'
/Users/tomwilliams/Projects/incard-rails/bin/rails:9:in `<top (required)>'
/Users/tomwilliams/Projects/incard-rails/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)Now, I can just "fix" it by running the migrate command again, or as I did, rollback the migrations and put the added column in the create table migration and deleting the add_column migration.
My question is - does anybody know if this is a known issue, and if so, could someone provide a link.--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com .
To post to this group, send email to rubyonra...@googlegroups.com .
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .1eb04bc6-7c56-4555-a90e- 47b18a2f8d60%40googlegroups. com
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8ac451f6-3513-49a0-b7ed-93034b46a582%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment