rake db:migrate 产生“rake 中止!找不到表”错误

2023-11-26

我是 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

*** 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

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

或者这里是否存在某种宝石依赖性问题?我注意到“faker” gem 显示在错误列表的顶部,尽管除了我的测试之外我什至没有真正使用它(从 Michael Hartl 的 RailsTutorial.org 复制)。

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

迪恩·理查森 Genlighten.com


过去几周我一直在从事的一个业余项目中遇到了这个问题。当我跑步时,答案才变得清晰rake db:migrate with --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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

rake db:migrate 产生“rake 中止!找不到表”错误 的相关文章

随机推荐

  • VS2013:查找资源字典时出错

    我刚刚拿到VS2013并打开了我的VS2010项目 但是现在我看不到任何 xaml 设计 问题是样式没有被应用
  • 添加多个浮点变量时最小化浮点误差

    在我的 C 应用程序中 我有一个范围 0 1 内的双精度向量 我必须尽可能准确地计算其总数 感觉这个问题之前应该已经解决了 但我找不到任何东西 显然 如果向量大小很大并且有些项目明显小于其他项目 则迭代向量上的每个项目并执行 sum vec
  • 播种default_random_engine?

    我使用的是 Visual Studio 2010 不支持
  • 如何编写 cpp __DIR__ 宏,类似于 __FILE__

    The FILE and LINE 宏内置于C预处理器 通常用于打印带有文件名和行号的调试输出 我需要类似的东西 但只有路径末尾的目录名称 例如 如果我的代码位于 home davidc some path to some code foo
  • Mobile safari 对大图像进行下采样。如何挽留?

    我有一个 HTML 页面 其中包含 1675 像素 x 2640 像素的图像 我尝试在 iPad 上查看它 显然移动 safari 降低了图像的采样率 我们想要展示高质量的图像 但 Safari 限制了这一点 我一直在寻找保留图像大小的解决
  • Java中文件名的编码

    我正在嵌入式 Linux 平台上运行一个小型 Java 应用程序 将Java VM JamVM替换为OpenJDK后 带有特殊字符的文件名无法正确存储 特殊字符 如变音符号 将替换为问号 这是我的测试代码 import java io Fi
  • 为什么反应本机项目是在打字稿中创建的?我想要app.js

    我是 React Native 的初学者 我正在使用 React Native CLI 创建一个 React Native 项目 但项目是使用 app ts 创建的 我想在 javascript 版本中创建项目 我尝试过 React Nat
  • 多重继承不明确的基类

    考虑代码 struct Base struct Derived public Base struct A public Base struct B public A public Base struct C public A public
  • 如何限制 jQuery 事件的回调?

    好的 所以我像在谷歌中一样进行搜索 您在输入中键入文本 它会立即为您提供条目 但我不喜欢这样 我用类似的东西 TEXTINPUT keyup function 当用户输入速度非常快时 它会多次连接到数据库 是否有可能 只有当用户停止输入 1
  • 等待 Workbook.RefreshAll() (C#)

    我想循环遍历一个目录 使用 C 并刷新其中的所有 Excel 工作表 我用 Workbook RefreshAll 我该如何等待Workbook RefreshAll 声明结束 问题是 我打开FileA then Workbook Refr
  • 一个 Java 类中最多可以使用多少个 lambda?

    这是一个纯粹概念性的问题 Java 8 中的 Lambda 被转换为使用以下方式调用的方法invokedynamic 如果 JVM 对一个类可以拥有的最大方法数有限制 这是否意味着一个类中使用的 lambda 最大数量也受到 JVM 的严格
  • 使用 redux 时,应该如何在 React 组件中处理取消订阅?

    在我的组件中 我有以下内容 componentWillMount function this unsubscribe store subscribe function this setState message store getState
  • 如何将Scala Squeryl ORB与play 2.0框架集成?

    我正在尝试将 Squeryl ORB 与 play 2 0 框架一起使用 但是在调用时DB getConnection 在初始化期间我得到 BadPath 路径参数 无效路径 找不到defaultdb的数据源 路径表达式中不允许使用令牌 如
  • 从 device_vector 中删除元素

    推力 device vector 值 推力 device vector 键 初始化后 keys包含一些等于 1的元素 我想删除键中和值相同位置的元素 但不知道并行如何处理 可能有很多方法可以做到这一点 一种可能的方式 使用模板版本thrus
  • Android WebSocket 服务进行多个连接

    我创建了一个 Web 套接字服务 但它不断建立多个连接 我只希望应用程序建立一个连接 除非网络连接断开然后建立另一个连接 但现在 如果我按下手机上的主页按钮 它就会建立一个连接 然后返回应用程序 它将建立另一个连接 谢谢你们的帮助 在创建
  • GNU Parallel:将文件拆分为子文件

    Goal 使用 GNU Parallel 将大 gz 文件拆分为子文件 由于服务器有 16 个 CPU 因此创建 16 个子级 每个子项最多应包含 N 行 这里 N 104 214 420 行 子项应采用 gz 格式 输入文件 名称 fil
  • 获取字符串“600sp”整数部分的最佳方法?

    我有一个字符串 比如 600sp 我希望从中获取整数部分 600 If I do Integer valueOf 600sp 由于字符串中遇到非数字值 s 我收到异常 获取整数部分最快最干净的方法是什么 Thanks 如果您的字符串格式始终
  • 如何在带有参数的 Swift 块中正确处理 Weak Self

    In my TextViewTableViewCell 我有一个变量来跟踪块和一个配置方法 其中块被传入并分配 这是我的TextViewTableViewCell class TextViewTableViewCell swift impo
  • 启用急切执行时不支持 tf.gradients。使用 tf.GradientTape 代替

    from tensorflow keras applications import VGG16 from tensorflow keras import backend as K model VGG16 weights imagenet i
  • rake db:migrate 产生“rake 中止!找不到表”错误

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