Ho lavorato a un'applicazione Rails 4.0 con sqlite (predefinito per Rails ambiente di sviluppo) per eventi (hackathon) che ha un modello principale, Evento, per il quale possono esserci molti Press_Blurbs.Rails 4: schema.db mostra "Could not dump table" eventi "a causa di NoMethodError # metodo undefined` [] 'per nil: NilClass "
Per prima cosa ho corse alcuni generatori di ponteggio che ha creato alcuni migrazioni che ho incontrato, apparentemente senza alcun problema:
class CreateEvents < ActiveRecord::Migration
def change
create_table :events do |t|
t.string :city
t.string :theme
t.datetime :hackathon_start
t.datetime :hackathon_end
t.datetime :show_start
t.datetime :show_end
t.text :about
t.string :hack_rsvp_url
t.string :show_rsvp_url
t.timestamps
end
end
end
class CreatePressBlurbs < ActiveRecord::Migration
def change
create_table :press_blurbs do |t|
t.string :headline
t.string :source_name
t.string :source_url
t.string :logo_uri
t.timestamps
end
end
end
Poi ho aggiunto alcune relazioni ai modelli:
class Event < ActiveRecord::Base
has_many :press_blurbs
end
class PressBlurb < ActiveRecord::Base
belongs_to :event
end
... e ha aggiunto/ha eseguito una migrazione per aggiungere un riferimento tabella:
class AddEventRefToPressBlurbs < ActiveRecord::Migration
def change
add_column :press_blurbs, :event, :reference
end
end
Tuttavia, quando guardo a schema.db questo è quello che vedo, invece di definizioni tavoli:
# Could not dump table "events" because of following NoMethodError
# undefined method `[]' for nil:NilClass
# Could not dump table "press_blurbs" because of following NoMethodError
# undefined method `[]' for nil:NilClass
Altre tabelle non correlate visualizzati in schema.rb perfettamente bene, ma questi non lo faccio. Qualche idea su cosa sta succedendo?
Quando si esegue 'rake db: migrate' lo schema si aggiorna? –
No. :(Il file rimane lo stesso del numero di versione – huertanix