gpt4 book ai didi

ruby-on-rails - rake db :migrate produces "rake aborted! could not find table" error

转载 作者:行者123 更新时间:2023-12-04 04:54:52 25 4
gpt4 key购买 nike

我是Rails的新手,并且正在为我的雇主构建一个简单的项目跟踪应用程序。我一直在Mac上开发该应用程序,并将其推送到github。我只是设法将github存储库克隆到公司防火墙后面的Windows盒中,希望让同事试用该应用程序。

但是,当我转到rake db:migrate在Windows框中初始化数据库时,出现以下错误消息:

$ 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

我的 gem list 如下所示:
$ 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)

我在Windows框中的schema.rb文件如下所示:
# 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

由于这是我第一次在此计算机上运行迁移,因此我希望迁移过程中的任何内容在创建之前都不应尝试访问“项目”表。但是我注意到,直到几个与之关联的表( Assets ,宏帖子)之后,schema.rb中才列出“项目”表。这是问题的根源吗?

还是在这里有某种 gem 依赖问题?我注意到,“faker” gem出现在错误列表的顶部,即使我在测试中什至没有真正使用它(从Michael Hartl的RailsTutorial.org复制)。

感谢您提供的任何帮助或建议!

院长理查森
Genlighten.com

最佳答案

在过去的几个星期中,我一直在进行的一个辅助项目中遇到了这个确切的问题。当我用rake db:migrate运行--trace.时,答案才对我很清楚。在那里,我注意到堆栈跟踪提示factory_girl无法实例化丢失的表项。

我进入了factory.rb文件并删除了有问题的模型,之后我就可以运行rake db:migrate了。另外,对我来说,问题是:

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

在这种情况下,工厂内部的工厂正试图在 rake 任务期间插入。由于该表不存在,所以它被炸掉了。在一点帮助下,我发现执行此操作的正确方法是:
Factory.define :table1 do |b|
b.name "table1"
b.rating 5
b.table2_relation {Factory(:table2)}
end

关于ruby-on-rails - rake db :migrate produces "rake aborted! could not find table" error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3761622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com