Laravel supports many database connections such as MySQL, PostgreSQL, SQL Server and SQLite. Most of the time we use either MySQL or PostgreSQL. But if we need, we can easily change the default database connection of a Laravel application to SQLite. SQLite is a file based database and it is suitable for small projects. To change the connection, first, open the
.env file and change the
sqlite. Comment or completely remove other database configuration lines like this.
Then we need to create a new file called
database.sqlite in the
database directory by running the following command.
Now check whether the SQLite database has been successfully detected or not by Laravel. For that, run the
php artisan migrate:status
If you get a message called “Migration table not found.”, that means Laravel has successfully detected the
database.sqlite file and you are ready to run the migration. For that, run this
migrate Artisan command.
php artisan migrate
If you get the “Database does not exist.” or similar error, try to follow the How To Fix Laravel SQLite “Database does not exist” to fix it. Otherwise, it should create all the necessary tables in the SQLite database.