2010-09-21 6 views
8

Sono nuovo di Rails e sto creando una semplice app di tracciamento del progetto per il mio datore di lavoro. Ho sviluppato l'app sul mio Mac e l'ho spinta a github. Sono appena riuscito a clonare il mio repository Github in una finestra di Windows dietro il firewall della mia azienda, nella speranza di consentire ai colleghi di provare l'app.rake db: migrazione produce errore "rastrello interrotto impossibile trovare la tabella"

Ma quando vado a rake db: migrate per inizializzare il database sulla scatola di Windows, ottengo i seguenti messaggi di errore:

$ rake db:migrate --trace 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
rake aborted! 
Could not find table 'projects' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/connection_adapters/sqlite3_adapter.rb:29:in `table_structure' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/faker-0.3.1/lib/extensions/object. 
rb:3:in `returning' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/connection_adapters/sqlite3_adapter.rb:28:in `table_structure' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/connection_adapters/sqlite_adapter.rb:228:in `columns' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/base.rb:1271:in `columns' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/base.rb:1279:in `columns_hash' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/base.rb:1578:in `find_one' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/base.rb:1569:in `find_from_ids' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco 
rd/base.rb:616:in `find' 
c:/Rails_Projects/molex_app/config/routes.rb:15 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro 
ller/routing/route_set.rb:226:in `draw' 
c:/Rails_Projects/molex_app/config/routes.rb:1 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup 
port/dependencies.rb:145:in `load_without_new_constant_marking' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup 
port/dependencies.rb:145:in `load' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup 
port/dependencies.rb:521:in `new_constants_in' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup 
port/dependencies.rb:145:in `load' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro 
ller/routing/route_set.rb:286:in `load_routes!' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro 
ller/routing/route_set.rb:286:in `each' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro 
ller/routing/route_set.rb:286:in `load_routes!' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro 
ller/routing/route_set.rb:266:in `reload!' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:537 
:in `initialize_routing' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:188 
:in `process' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113 
:in `send' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113 
:in `run' 
c:/Rails_Projects/molex_app/config/environment.rb:9 
c:/RubyonRails/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in ` 
gem_original_require' 
c:/RubyonRails/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in ` 
require' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup 
port/dependencies.rb:156:in `require' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup 
port/dependencies.rb:521:in `new_constants_in' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup 
port/dependencies.rb:156:in `require' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/tasks/misc.rake:4 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `cal 
l' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `exe 
cute' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `eac 
h' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `exe 
cute' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `inv 
oke_with_call_chain' 
c:/RubyonRails/Ruby187/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `inv 
oke_with_call_chain' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `inv 
oke_prerequisites' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `eac 
h' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `inv 
oke_prerequisites' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in `inv 
oke_with_call_chain' 
c:/RubyonRails/Ruby187/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `inv 
oke_with_call_chain' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `inv 
oke' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `in 
voke_task' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `to 
p_level' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `ea 
ch' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `to 
p_level' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `st 
andard_exception_handling' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `to 
p_level' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `ru 
n' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `st 
andard_exception_handling' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `ru 
n' 
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31 
c:/RubyonRails/Ruby187/bin/rake:19:in `load' 
c:/RubyonRails/Ruby187/bin/rake:19 

Mia lista gemme si presenta così:

$ gem list 

*** LOCAL GEMS *** 

actionmailer (2.3.5) 
actionpack (2.3.5) 
activerecord (2.3.5) 
activeresource (2.3.5) 
activesupport (2.3.5) 
faker (0.3.1) 
rack (1.0.1, 1.0.0) 
rails (2.3.5) 
rake (0.8.3) 
sqlite3-ruby (1.3.0 x86-mingw32) 
will_paginate (2.3.12) 

Il mio file schema.rb sulla finestra di Windows assomiglia a questo:

# This file is auto-generated from the current state of the database. Instead of editing this file, 
# please use the migrations feature of Active Record to incrementally modify your database, and 
# then regenerate this schema definition. 
# 
# Note that this schema.rb definition is the authoritative source for your database schema. If you need 
# to create the application database on another system, you should be using db:schema:load, not running 
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations 
# you'll amass, the slower it'll run and the greater likelihood for issues). 
# 
# It's strongly recommended to check this file into your version control system. 

ActiveRecord::Schema.define(:version => 20100915193510) do 

    create_table "assets", :force => true do |t| 
    t.integer "project_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "image_file_name" 
    t.string "image_content_type" 
    t.integer "image_file_size" 
    t.datetime "image_updated_at" 
    end 

    create_table "macroposts", :force => true do |t| 
    t.text  "content" 
    t.integer "user_id" 
    t.integer "project_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    create_table "projects", :force => true do |t| 
    t.string "title" 
    t.integer "status",    :limit => 255 
    t.integer "program_manager_id" 
    t.integer "design_engineer_id" 
    t.string "sales_engineer" 
    t.string "customer" 
    t.string "market_size" 
    t.string "project_code" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    add_index "projects", ["design_engineer_id"], :name => "index_projects_on_design_engineer_id" 
    add_index "projects", ["program_manager_id"], :name => "index_projects_on_program_manager_id" 

    create_table "statuses", :force => true do |t| 
    t.string "status_name" 
    t.integer "status_code" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    create_table "users", :force => true do |t| 
    t.string "name" 
    t.string "email" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "encrypted_password" 
    t.string "salt" 
    t.string "remember_token" 
    t.boolean "admin",    :default => false 
    t.string "avatar_file_name" 
    t.string "avatar_content_type" 
    t.integer "avatar_file_size" 
    t.datetime "avatar_updated_at" 
    end 

    add_index "users", ["email"], :name => "index_users_on_email", :unique => true 
    add_index "users", ["remember_token"], :name => "index_users_on_remember_token" 

end 

Poiché questa è la prima volta che corro migrazioni su questa macchina, mi aspetto che nulla del processo di migrazione debba cercare di accedere alla tabella "progetti" prima che venga creata. Ma noto che la tabella "projects" non è elencata in schema.rb fino a dopo diverse tabelle ad essa associate (assets, macroposts). È questa la fonte del problema?

O è una sorta di problema di dipendenza della gemma al lavoro qui? Ho notato che la gemma "faker" compare verso l'alto nell'elenco degli errori, anche se non la uso nemmeno nei miei test (copiata da Michael Hartl's RailsTutorial.org).

Grazie per qualsiasi aiuto o suggerimento che puoi offrire!

Dean Richardson Genlighten.com

risposta

0

potrebbe voler cercare di rake db:create anche assicurarsi che i file di configurazione siano corretti nell'indicare al server SQL che si desidera.

Assicurati anche che tutti i file di migrazione abbiano un bell'aspetto e non abbiano errori di sintassi o qualcosa del genere.

+0

I file environment.rb e database.yml sembrano puntare a sqlite3 e alla gemma sqlite3-ruby appropriata. È possibile che i miei file sqlite3 siano in qualche modo incompatibili con i miei altri file Rails, ma se così fosse, non è ovvio come. I miei file di migrazione funzionano su altre macchine, quindi sono abbastanza sicuro di loro. – hikari17

+0

Ho eliminato il database di sviluppo vuoto e ho eseguito rake db: creare come suggerito. Questa volta non è stato generato alcun errore "Impossibile trovare la tabella". Ho quindi provato ad avviare il server ("ruby script/server") e ho ottenuto un altro lungo errore dump che iniziava con "Impossibile trovare i" progetti "tabella. Quindi il problema di base è ancora lì. – hikari17

+0

devi eseguire le migrazioni dopo aver creato il database, quindi eseguirò 'rake db: migrate' dopo aver eseguito' rake db: create' – Jimmy

13

Ho avuto questo problema esatto per le ultime settimane in un progetto parallelo su cui ho lavorato. La risposta mi è apparsa solo quando ho eseguito rake db:migrate con --trace. Una volta lì ho notato che la traccia dello stack si stava lamentando del fatto che factory_girl non fosse in grado di creare un'istanza dell'oggetto della tabella mancante.

Sono andato nel mio file factory.rb e rimosso il modello incriminato e successivamente sono stato in grado di eseguire rake db:migrate. Inoltre, il problema per me era:

Factory.define :table1 do |b| 
    b.name "table1" 
    b.rating 5 
    b.table2_relation Factory(:table2) 
end 

In questo caso la fabbrica all'interno della fabbrica stava tentando di inserire durante il compito rastrello. Dal momento che il tavolo non esisteva ancora, è esploso. Con un piccolo aiuto ho trovato che il modo corretto per farlo è:

Factory.define :table1 do |b| 
    b.name "table1" 
    b.rating 5 
    b.table2_relation {Factory(:table2)} 
end 
+1

Grazie –

+1

Qualche idea sul perché la factory girl dovrebbe fare qualcosa di simile durante lo schema: caricare in primo luogo? Non dovrebbe schema: caricare solo use database.yml e schema.rb? – bchurchill

5

Ho appena incontrato lo stesso problema. rake db:create funzionerebbe, ma l'esecuzione di qualsiasi altra cosa, come rake db:schema:load o rake db:migrate, non è riuscita con un errore su una tabella mancante. La risposta di Chris Hein mi ha indirizzato nella giusta direzione. La tabella mancante veniva referenziata nelle specifiche e, per qualche motivo, venivano caricate come parte dell'ambiente prima dell'esecuzione delle attività di rake. Ho appena spostato la cartella delle specifiche, eseguito le attività di rake e spostato di nuovo.

+1

Che Era esattamente quello che mi era successo, quindi seguendo quello che hai detto ho commentato il codice in un file di inizializzazione (scusami l'ortografia inglese) con il codice che fa riferimento a quel modello, quindi 'rake db: schema: load' (perché solo' rake db: mi grattugiare' era ancora nei guai), e voilà !, ha funzionato. Grazie! – mjnissim

0

Aveva un problema simile e aveva a che fare con factory_girl come fece notare Chris.In questo modo mi sembra un modo più semplice per risolverlo:

In Gemfile, definire fabbrica ragazza come questa:

gem 'factory_girl_rails', :require => false 

Poi, nel file di spec_helper.rb:

require 'factory_girl_rails' 

Ecco il link per risposta originale: FactoryGirl screws up rake db:migrate process