I tried to remake my previously created Laravel 8 project with the latest version of Laravel 12. After setting up the database connection (PostgreSQL), it threw an error:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "sessions" does not exist
I already updated the .env file:
DB_CONNECTION=pgsql
and in config/database.php file:
'default' => env('DB_CONNECTION', 'postgres'),
...
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5434'),
'database' => env('DB_DATABASE', 'library'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', 'postgres123!@#'),
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => 'prefer',
],
For more information: I am using fresh installed wampserver 3.3.7, PHP 8.3.14, Laravel 12.14.1 and already enabled the extension pdo_pgsql and pgsql from php.ini. The version of PotgreSQL is 12 and it indeed using the right port (5434) instead the default 5432. The previously created project works fine with those setting.
As for the reason I choose to remake it instead of following the upgrade guide from Laravel is because there are many lines of codes that I need to optimize, and it's faster to recreate it from the beginning.
The error tells you that you are querying a sessions
table which does not exist. To creata the sessions
table, you need to run
php artisan session:table
and then
php artisan migrate
however, before you do so, check config/database.php to see whether you have a table prefix and if so, make sure you are not ignoring whatever prefix is defined there. Also, make sure you know what you are doing. Session handling is supported in multiple manners in Laravel:
Cookie. Stores session data in encrypted cookies.
Database. Stores sessions in a database (MySQL, PostgreSQL, SQLite).
Cache (Memcached/Redis). Stores sessions in cache for faster access.
DynamoDB. Uses AWS DynamoDB for storage, which is ideal for scalable applications.
File. Saves session data in Laravel’s filesystem.
Array. Stores session data in memory; useful for testing but isn’t persistent.
Read more here.