找不到表“用户" [英] Could not find table 'users'

查看:42
本文介绍了找不到表“用户"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新 4

请参阅下面的解决方案!

See solution below!

**更新 3 **

如果有人真的还在读这篇文章(我很感激!)我今天一直在为我的代码苦苦挣扎(是的,仍然是一个菜鸟,在 ruby​​ on rails 教程的第 11 章).

If anyone is actually still reading this (I appreciate it!) I've been struggling around my code today (yes still a noob and in chapter 11 of the ruby on rails tutorial).

我应该重置回上次提交:

I've supposedly reset back to my last commit:

$ cd rails_screencast/sample_app/
$ git reset --hard 2396c0d288d132ffc43c82d5cbbc736a5258eed2
HEAD is now at 2396c0d Micropost Validations

当我在本地主机上检查站点时,它实际上显示的是用户列表而不是 ERROR 页面,但是当我运行测试套件时(使用 spork 进行自动测试 - 我也重置了几次以确保)我仍然获取所有错误,如下所示.我很好奇找不到表'用户'",因为它出现在每个错误中#

When I check the site on local host it actually shows a list of users and not an ERROR page but when I run the test suite (autotest with spork - I've reset those a few times too to be sure) I still get all errors such as these shown below. I'm very curious about the "Could not find table 'users'" as it is in EVERY error #

  108) Users signin success should sign a user in and out
     Failure/Error: user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/requests/users_spec.rb:56:in `block (4 levels) in <top (required)>'

Finished in 0.9872 seconds
108 examples, 108 failures

是时候继续插入并查看所有这些错误了,如果有人能提供任何见解或提示或想法来检查什么,我将不胜感激!或者,如果您需要其他信息,我也可以发布该信息(只需非常具体地说明要查看哪些文件,因为我对行话的掌握程度并不像很多人一样)

Time to keep on plugging and looking at all these errors, if anyone can offer any insight or hints or ideas what to check I would appreciate it! Or if you need additional information I can post that too (just be very specific to which files to see as I'm not totally fluent in the lingo as many are already)

更新 2:

似乎我的重置与出厂设置有些混乱,因为有时我所有的错误都指向我的 micropost_spec.rb 文件的第 5 行@@user = Factory(:user) 行......几乎就像我的工厂文件不再链接到任何内容.我想知道 rake db:migrate 是否会解决我的任何问题……或者只是创造新问题……我只有用 faker 填充的示例数据

It seems that my reset messed something up with the factory settings as sometimes all my errors are pointing to line 5 of my micropost_spec.rb file specifically @ the @user = Factory(:user) line... almost like my factories file isn't linked to anything any more. I am wondering if a rake db:migrate would solve any of my problems... or just create new problems... I only have sample data filling in with faker

有什么想法吗?

是否可以将我的文件系统恢复到以前的提交并重新开始?...当我是绿色的

Is it possible to revert my file system back to a previous commit and start over? ... when I was green

Failures:

  1) Micropost should create a new instance with valid attributes
     Failure/Error: @user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'

  2) Micropost user associations should have a user attribute
     Failure/Error: @user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'

  3) Micropost user associations should have the right associated user
     Failure/Error: @user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'

  4) Micropost validations should have a user id
     Failure/Error: @user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'

  5) Micropost validations should require nonblank content
     Failure/Error: @user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'

  6) Micropost validations should reject long content
     Failure/Error: @user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'

更新 1:

我收到了从 4 到 6 到 111 的错误,所有的错误都是重复出现的

I'm getting errors from 4 to 6 to 111 all with a recurring theme of

 1) Micropost should create a new instance with valid attributes
     Failure/Error: @user = Factory(:user)
     ActiveRecord::StatementInvalid:
       Could not find table 'users'
     # ./spec/models/micropost_spec.rb:53:in `block (2 levels) in <top (required)>'

特别是找不到表‘用户’"——我从教程 git 中复制了 micropost_spec.rb 文件的代码,但似乎没有修复它——也许有人可以帮助我了解表所指的内容到?

Specifically the "Could not find table 'users'" - I copied the code from the tutorial git for the micropost_spec.rb file but didn't seem to fix it- maybe someone can help direct me to what the table is referring to?

////////////////////////////////////原文如下///////////////////////////////

////////////////////////////////////// ORIGINAL BELOW ////////////////////////////////

我正在学习 Ruby on Rails 教程第 11 课,并尝试填充我的数据库以显示微博

I am working in the Ruby on Rails Tutorial lesson 11 and am trying to populate my db to show the microposts

当我执行 rake db:populate 命令时,它给了我以下信息:

when I did the rake db:populate command it gave me the following:

    macbook:sample_app macbook$ rake db:populate
(in /Users/macbook/rails_screencast/sample_app)
db/test.sqlite3 already exists
db/test.sqlite3 already exists
db/development.sqlite3 already exists
-- create_table("microposts", {:force=>true})
   -> 0.0090s
-- add_index("microposts", ["user_id"], {:name=>"index_microposts_on_user_id"})
   -> 0.0074s
-- create_table("users", {:force=>true})
   -> 0.0243s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
   -> 0.0094s
-- initialize_schema_migrations_table()
   -> 0.0167s
-- assume_migrated_upto_version(20110614132314, "db/migrate")
   -> 0.0432s
rake aborted!
Validation failed: Email is invalid

我运行了几次,一直遇到同样的错误...当我在浏览器上访问该网站时,我的示例用户似乎都不在那里...

I ran it a couple times and kept getting the same error... when I visited the site on a browser it was like none of my sample users were there...

require 'faker'


namespace :db do 
  desc "Fill database with sample data"
  task :populate => :environment do
    Rake::Task['db:reset'].invoke
    admin = User.create!(:name => "Foo Bar",
                         :email => "foo@bar.com",
                         :password => "foobar",
                         :password_confirmation => "foobar")
   admin.toggle!(:admin)
    99.times do |n|
      name = Faker::Name.name
      email = "example-#{n+1}@railstutorial.org"
      password = "password"
      User.create!(:name => name,
                   :email => email,
                   :password => password,
                   :password_confirmation => password)
    end

    User.all(:limit => 6).each do |user|
      50.times do
        user.microposts.create!(:content => Faker::Lorem.sentence(5))
      end
    end
  end
end

然后我决定哦,也许 rake db:reset 会清除我的示例数据库,我可以用新鲜的东西再次运行填充...糟糕的假设

then I decided oh maybe rake db:reset will purge my sample database and I can run the populate again with fresh stuff... bad assumption

我的测试套件现在显示:

my test suite now shows:

Finished in 0.99915 seconds
111 examples, 111 failures

现在,在我把更多事情搞砸之前,我正在寻找下一步该去哪里的建议......

Now before I mess more stuff up I'm looking for some advice where to go next ...

推荐答案

Michael(railstutorial.org 的作者)回复了我的电子邮件请求!

Michael (author of the railstutorial.org) responded to my email request!

如果您在运行测试套件时丢失了一个表,则可能表明您需要运行:

rake db:test:prepare

是的!!YYYY

Finished in 4.82 seconds
108 examples, 0 failures

蛋糕时间!

这篇关于找不到表“用户"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆