keizah
6 months ago
1688
9
Testing

SQLite foreign key dont set null on delete in phpunit test

Posted 6 months ago by keizah

Hello,

I have migration where I add foreign key to threads table (https://github.com/keizah7/forum/commit/e1aa1b31555c9469091be178e23f5746c377c080#diff-873a697d9df8d6d454c40acbb165080e) Problem is that in phpunit test sqlite don't set foreign key null on delete.

1) Tests\Feature\BestReplyTest::if_a_best_reply_is_deleted_then_the_thread_is_properly_updated_to_reflect_that
Failed asserting that '1' is null.

For temporary solution I do it manually - I am using model static::deleted and then test is passing.

Where is the problem? Jeffrey covered this topic in https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/82 but his solution doesn't help me. I'm using Laravel 7.3 and foreign_key_constraints is true by default.

Please sign in or create an account to participate in this conversation.