Home » Php » php – Laravel testing, no such table, sqlite

php – Laravel testing, no such table, sqlite

Posted by: admin July 12, 2020 Leave a comment


I am running Laravel, on OS X using MAMP, and I am trying to do some unit testing, using PHPUnit, and sqlite, however when I run my tests, I get the error

General error: 1 no such table: users

I’ve tried running the artisan, to manually migrate the database, using the –env=testing, which runs fine, however I still get the error. I even call Artisan::call('migrate'); in the SetUp method.


return [
    'default' => 'sqlite',

    'connections' => [
        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => ''

Migration file:

Schema::create('users', function($table) {
    $table->string('email', 32)->unique();
    $table->string('password', 64);
    $table->string('username', 32)->unique();
    $table->enum('status', array('ACTIVE', 'INACTIVE'));

Schema::create('roles', function($table) {
    $table->string('name', 32);

Schema::create('role_user', function ($table) {



How to&Answers:

SQLite doesn’t support the ENUM type : http://www.sqlite.org/datatype3.html

That’s why the users table isn’t created. You will have to run your tests on a classic MySQL table or remove all the ENUM types.


Running migrations before running the test doesn’t work because, as your config shows, you db is in memory, so every time you run a new test, it runs migrations for each testing session and completely destroys all testing data when it finishes.

To use the memory database, run your migrations each time you run your tests, extend your classes from TestCase with something like:


class TestCase extends Illuminate\Foundation\Testing\TestCase {

  public function createApplication()
      $unitTesting = true;
      $testEnvironment = 'testing';
      return require __DIR__.'/../../bootstrap/start.php';

  public function setUp()
  private function prepareForTests()
  public function tearDown()