7

I've started learning rails3 few days ago, and since today, every time I run unit test for my model I get this error message:

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: users: DELETE FROM "users" WHERE 1=1

The tests went smoothly yesterday, I run them today (reverting everything to the state from the time they were working)... and I'm still getting the error.

I'm using rails 3 release on Windows7 64 bit, SQLite 3.7.2, ruby 187 (but I do have many ruby installations - using pik to select 187)

Any ideas on fixing this issue?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
dahpgjgamgan
  • 2,977
  • 4
  • 25
  • 26

2 Answers2

14

If you created the model using a rails generator, you may have left over fixture files that are trying to access a table that isn't there anymore. For me, deleting the yml file solved the issue.

This was answered here: https://stackoverflow.com/a/6222934

Community
  • 1
  • 1
Sauce McBoss
  • 6,567
  • 3
  • 20
  • 22
  • Fixtures often get loaded into models; If a table no longer exists, you will get this error; Remove the fixtures that load into the non-existant table; – FlyingV Dec 20 '16 at 04:08
  • Yeah, or it may happen if you have renamed some models, and not renamed the fixture files as well. – Magne May 16 '17 at 13:35
11

It would be worth checking that your test database is set up correctly using the schema from your development database. You can achieve this with:

rake db:test:prepare
Shadwell
  • 34,314
  • 14
  • 94
  • 99