Laravel4 Seeding in testing environment fails using SQLite, while succeeds using mysql
NickName:brazorf Ask DateTime:2013-10-04T07:12:09

Laravel4 Seeding in testing environment fails using SQLite, while succeeds using mysql

In short: seeding is working fine with mysql while breaks with sqlite. The broken code is like DB::table('user')->insert($users);

Seed code:

<?php
public function run() {
    DB::table('user')->delete();
    $users = array();
    $birth = new DateTime('1980-03-12');
    while ($i++ < 50) {
        $users[$i]['email'] = "[email protected]";
        $users[$i]['password'] = User::password('test');
        $users[$i]['enabled'] = 1;
        $users[$i]['name'] = 'Name';
        $users[$i]['surname'] = 'Surname';
        $users[$i]['birthDate'] = $birth;
    }
    DB::table('user')->insert($users); //<- This line is broken when using sqlite.
}

My default database driver is mysql, now i am trying to switch to sqlite for the testing environment. So, under

app/config/testing/database.php

i have this config, inside 'connections' ('default' key is 'sqlite')

'sqlite' => array(
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ),

Now, if i issue

php artisan migrate --seed, this is working fine.

If i issue

php artisan migrate --seed --env=testing, this is NOT working

The DB::table('user')->insert($users); above is failing, infact when i comment that out the seeding works fine. The error at command line is

ErrorException","message":"array_keys() expects parameter 1 to be array, null given [...] /laravel/framework/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php","line":52

What's wrong here?

Copyright Notice:Content Author:「brazorf」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19170649/laravel4-seeding-in-testing-environment-fails-using-sqlite-while-succeeds-using

More about “Laravel4 Seeding in testing environment fails using SQLite, while succeeds using mysql” related questions

Laravel4 Seeding in testing environment fails using SQLite, while succeeds using mysql

In short: seeding is working fine with mysql while breaks with sqlite. The broken code is like DB::table('user')-&gt;insert($users); Seed code: &lt;?php public function run() { DB::table('use...

Show Detail

Laravel4 seed specific environment

We're are developing multiple applications based on Laravel 4. These applications run on the same webserver. The Laravel4 environment detection is based on the hostname which sucks because we have

Show Detail

Are acceptance tests in Codeception supposed to run in testing environment? (Laravel4 + Codeception)

I am trying to run some acceptance tests in my Laravel application. While functional tests trigger testing environment, acceptance tests do not. Is it a bug or a feature of acceptance tests? The main

Show Detail

Seeding SQLite RANDOM()

Does SQLite support seeding the RANDOM() function the same way MySQL does with RAND()? $query = "SELECT * FROM table ORDER BY RAND(" . date('Ymd') . ") LIMIT 1;"; From the MySQL Manual about RAND...

Show Detail

Gedmo\Tree test: SQLite fails, MySQL passes

In a simple test of a Category tree using SQLite, the test fails during setup with AppBundle\Tests\Entity\CategoryTest::testSetProductCategory() Doctrine\DBAL\DBALException: An exception occu...

Show Detail

Eloquent Model Events in Laravel 5.1 Testing Environment

I have an Eloquent model for which I have some observer methods defined in the model's boot() method. It's a very simple logic - I use the creating() static method to define a default value for an

Show Detail

Mariadb match against a view fails; succeeds in MySql

The fulltext search query below fails in mariadb, but succeeds in mysql (mariadb database imported from mysql database using phpmyadmin). If a base table is substituted, the query succeeds in both

Show Detail

artisan migration and seeding on sqlite in memory, always empty?

I'm trying to setup migration and seeding for a Laravel 5.4 application. Migration and seeding are working for mysql db. However when I try to run it on a sqlite in memory db, it seems to me that t...

Show Detail

Using SQLite for unit testing a mysql migrations setup

I want to use SQLite for PHPunit tests. We are using the mysql driver, so we have created our migrations based on that... meaning we are using nullables for default values. MYSQL doesn't care about...

Show Detail

Using now() for sqlite testing

I'm writing tests for my Laravel application and using MySQL for my development database but using SQLite in memory for my testing database with PHPUnit. I'm trying to write a query that will get...

Show Detail