gpt4 book ai didi

ruby-on-rails-3 - 找不到表 'users'

转载 作者:行者123 更新时间:2023-12-03 08:31:10 25 4
gpt4 key购买 nike

更新4

请参阅下面的解决方案!

**更新3 **

如果有人真的还在读这篇文章(我很感激!),我今天一直在挣扎着我的代码(是菜鸟,在ruby on rails教程的第11章中)。

我应该重置为我的最后一次提交:

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

当我检查本地主机上的站点时,它实际上显示的是用户列表,而不是错误页面,但是当我运行测试套件时(使用spork进行自动测试-我也已将其重置了几次,以确保),我仍然收到所有错误如下所示。我对“找不到表'users'”非常好奇,因为它出现在每个错误中#
  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

是时候继续插入并查看所有这些错误了,如果有人可以提供任何见解,提示或想法,请检查一下,我将不胜感激!或者,如果您需要其他信息,我也可以发布该信息(只是非常具体地查看要查看的文件,因为我不完全熟练使用术语,所以我已经不行了)

更新2:

似乎我的重置弄乱了出厂设置,因为有时我所有的错误都指向我的micropost_spec.rb文件的第5行,特别是@@ user = Factory(:user)行……几乎就像我的factory文件是“不再与任何事物联系起来。我想知道rake db:migrate是否可以解决我的任何问题...还是只是产生新的问题...我只用伪造者填写示例数据

有任何想法吗?

是否可以将文件系统恢复为先前的提交并重新开始? ...当我绿色的时候
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的错误,这些错误反复出现
 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)>'

特别是“找不到表'users'”-我从教程git复制了micropost_spec.rb文件的代码,但似乎没有解决它-也许有人可以帮助我把表指向什么?

//////////////////////////////////////原始下方/////////// //////////////////////

我正在Ruby on Rails教程第11课中工作,并试图填充我的数据库以显示微博

当我执行rake db:populate命令时,它给了我以下内容:
    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

我运行了几次,并不断遇到相同的错误...当我在浏览器上访问该网站时,好像没有一个示例用户在那儿...
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将清除我的示例数据库,然后我可以用新鲜的东西再次运行填充...错误的假设

我的测试套件现在显示:
Finished in 0.99915 seconds
111 examples, 111 failures

现在,在我弄乱其他东西之前,我正在寻找一些建议,下一步该怎么做...

最佳答案

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

如果在运行测试套件时缺少表,则可能表明您需要运行:

rake db:test:prepare

对!! YAYYYY
Finished in 4.82 seconds
108 examples, 0 failures

蛋糕时间!

关于ruby-on-rails-3 - 找不到表 'users',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6345319/

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