Ruby-on-rails ActiveRecord::StatementInvalid: 找不到表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7617760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:04:51  来源:igfitidea点击:

ActiveRecord::StatementInvalid: Could not find table

ruby-on-railsunit-testingrubymine

提问by Ava

I am trying to run users_test.rbfile which just has

我正在尝试运行users_test.rb刚刚有的文件

test "the truth" do
     assert true
   end

I do have a likes table, still I am getting this error. Why so?

我确实有一个喜欢表,但我仍然收到此错误。为什么这样?

Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
?  channelappnew  rake db:test:clone
?  channelappnew  rake db:test:clone_structure
?  channelappnew  rake db:migrate
?  channelappnew  rake db:test:load
?  channelappnew  rake db:test:prepare
?  channelappnew  rake db:test:purge
?  channelappnew  ruby -Itest test/unit/user_test.rb
Loaded suite test/unit/user_test
Started
E

Error:
test_the_truth(UserTest):
ActiveRecord::StatementInvalid: Could not find table 'likes'




Finished in 0.058371 seconds.

1 tests, 0 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
0% passed

17.13 tests/s, 0.00 assertions/s

Thanks!

谢谢!

回答by Hassan

before test do rake db:test:prepare

测试前做 rake db:test:prepare

回答by jbasko

Have you run rake db:migrate? Check database if the table exists. If you are working with sqlite, then call sqlite3 db/development.sqlite3and then issue command .schemaYou can manually delete database db/test.sqlite3and then re-create it with rake db:setup.

你跑了rake db:migrate吗?检查数据库是否存在表。如果您正在使用 sqlite,则调用sqlite3 db/development.sqlite3然后发出命令.schema您可以手动删除数据库db/test.sqlite3,然后使用rake db:setup.

回答by ryudice

Have you checked your fixtures? It has happened to me that I modified a migration but the fixture staid the same, therefore causing a error.

你检查过你的固定装置吗?我碰巧修改了迁移,但夹具保持不变,因此导致错误。

回答by narasappa

Sometimes it is caused due to multiple versions of active record gems. Please uninstall all gems except one that your application is using. I faced the same problem and did same what i said. It worked.

有时是由于活动记录 gem 的多个版本引起的。请卸载除您的应用程序正在使用的 gem 之外的所有 gem。我遇到了同样的问题,并按照我说的做了。有效。

回答by randomcontrol

I just had the same problem and found the solution in db/schema.rb:

我刚刚遇到了同样的问题,并在 db/schema.rb 中找到了解决方案:

# Could not dump table "xxx" because of following StandardError
#   Unknown type 'bool' for column 'yyy'

maybe this helps!

也许这有帮助!

"bool" worked everywhere except for this schema.rb, but the migrations where executed correctly in development mode.

除了这个schema.rb,“bool”在任何地方都可以使用,但是迁移在开发模式下正确执行。