So, I’m working along in Rails today, added a new migration, when all of a sudden tests that were passing only a few minutes ago suddenly start failing. The error I in rspec is something along the lines of:
1 2 3 |
Failure/Error: before { @event.update_attribute(:signup_deadline, 1.day.ago) } ActiveRecord::StatementInvalid: SQLite3::ConstraintException: event_signups.created_at may not be NULL: INSERT INTO "event_signups" DEFAULT VALUES |
In test.log:
1 2 |
[1m[35mSQL (0.5ms)[0m INSERT INTO "event_signups" DEFAULT VALUES SQLite3::ConstraintException: event_signups.created_at may not be NULL: INSERT INTO "event_signups" DEFAULT VALUES |
WTF? This was working only a few minutes ago.
If you google this, you will read endless others who experience the same error… when using HABTM relations. Well, EventSignup has no HABTM!
This has happened to me a couple of times, and each time it leaves me puzzled for far too many minutes, and there is no real solution.
Okay, well there is only one solution I have found to work: delete the SQLite database file and recreate. Yeah, that sux. Oddly enough, just a quick:
1 2 |
rm db/test.sqlite3 rake db:test:prepare |
And all is good again.
If anyone has an idea why this happens, I would love to hear why.