Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shiro_'s avatar

Laravel project not reading env file

I am setting up a laravel project, i have created a database and all the database details are correct in my env file. However, laravel seems not to be reading my .env file When i put the right or wrong credentials and run php artisan migrate or php artisan config:cache , i get this error

In Connection.php line 664:
                                                                                                                                           
  SQLSTATE[42601]: Syntax error: 7 ERROR:  zero-length delimited identifier at or near """"                                                
  LINE 1: select * from ""."facilities" where "subdomain" is null and ...                                                                  
                        ^ (SQL: select * from ""."facilities" where "subdomain" is null and ""."facilities"."deleted_at" is null limit 1)  
                                                                                                                                           

In Connection.php line 330:
                                                                                             
  SQLSTATE[42601]: Syntax error: 7 ERROR:  zero-length delimited identifier at or near """"  
  LINE 1: select * from ""."facilities" where "subdomain" is null and ...   

What could i be doing wrong? I have also enabled PDO in my php.ini file

My .env file looks like this :

APP_NAME="MedyQ"
APP_ENV=local
APP_KEY=*****
APP_DEBUG=true
APP_URL=http://medyq.localhost
APP_DOMAIN=medyq.localhost

LOG_CHANNEL=stack

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=medyq
DB_SCHEMA=medyq
DB_USERNAME=medyq
DB_PASSWORD=*****
0 likes
5 replies
s4muel's avatar

seems that the DB_SCHEMA is lost somewhere. what is your laravel version? if you are by any chance on old larvel version (5.4.3 or below), see this guys problem and try to debug if that is your case too

https://stackoverflow.com/questions/51052864/i-can-not-run-php-artisan-migrate you can put some breakpoints arout that part of the code and trace backe where in the way the DB_SCHEMA gets lost

another case here: https://github.com/laravel/framework/issues/17578 guy solved similar problem and said:

Edit: Added a primary key and solved the problem

1 like
MichalOravec's avatar

@s4muel What?! For you it's the solution change file in the vendor folder?

Never ever change file in the VENDOR folder!!!

Sinnbeck's avatar

Are you by any chance using env inside your code? If so then that wont work. Env should only be used in config.

If you use it in code, it will return null when caching is on.

Snapey's avatar

first off, any passwords in .env you should wrap in quotes

second, run php artisan config:clear and never run config:cache in development

third, check what laravel sees with tinker

>>> config('database')

This will show you the config parameters being used by laravel after the .env and database.php file have been merged

s4muel's avatar

@michaloravec of course, i didn't mean that, im going to clarify that reply so there is no implication of it

Please or to participate in this conversation.