I'm trying to test my app using phpunit with laravel but each time I run
unit test
vendor\bin\phpunit
All tables in my database drop so I have to migrate each time I run a test
Have you encountered with similar issue & how can I fix it ?
Use a separate connection for tests. Add this connection to config/database.php config file:
'connections' => [
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
Related
I am trying to connect django.db.backends.postgresql with my lumen application. But when I run the query then following error occured
could not find driver
Even I change the driver type from mysql to pgsql
My database connection
'ml_db' => [
'driver' => 'django.db.backends.postgresql',
'host' => env('ML_DB_HOST'),
'port' => env('ML_DB_PORT'),
'database' => env('ML_DB_NAME'),
'username' => env('ML_DB_USER'),
'password' => env('ML_DB_PASS'),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_general_ci'),
'prefix' => '',
'timezone' => env('DB_TIMEZONE', '+00:00'),
'strict' => false,
],
Is there any way to connect this database with my lumen application because I am using multiple databases in application.
The obvious answer here is, that you haven't installed the corresponding driver for your used dbms. So just install it.
from your configuration posted in the question, I assume that it's your lumen configuration. There is no 'django.db.backends.postgresql' driver in lumen. What we have is pgsql driver unless you create such a custom driver yourself,(which I assume is not the case).
so change the driver parameter to the following?
'driver' => 'pgsql',
Lumen .env file:
DB_CONNECTION=pgsql
DB_HOST=your host
DB_PORT=5432
DB_DATABASE=database
DB_USERNAME=username
DB_PASSWORD=password
The link
I want to use the sqlite db stored in "C:\Folder\my_database.sqlite" , what should i do? I want to use that sqlite db. Can anyone please suggest me a solution?
So i can give the path to sqlite in database.php below:
'sqlite' => [
'driver' => 'sqlite',
'database' => "path to my sqlite db",
'prefix' => '',
],
Also if that is done, then i can change my default connection to sqlite. Like:
DB::setDefaultConnection('sqlite');
Can anyone please suggest me a solution?
As the Laravel Documentation states:
After creating a new SQLite database using a command such as touch
database/database.sqlite, you can easily configure your environment
variables to point to this newly created database by using the
database's absolute path:
'sqlite' => [
'driver' => 'sqlite',
'database' => "C:\Folder\my_database.sqlite",
'prefix' => '',
],
To make it the default connection, just set this in your .env file:
DB_CONNECTION=sqlite
Open your .env file and set,
DB_CONNECTION=sqlite
DB_DATABASE=C:\Folder\my_database.sqlite
further more information you can see: https://laravel.com/docs/5.7/database
for set sqlite database you can add absoulate path like this in database.php file..
'sqlite' => [
'driver' => 'sqlite',
'database' => 'C:\Folder\my_database.sqlite',
'prefix' => '',
],
for set a default sqlite connection update this in your .env file:
DB_CONNECTION=sqlite
for production update line(number 16) in database.php
'default' => env('DB_CONNECTION', 'sqlite'),
and then run this command in terminal for remove old configration and create new configration file.
php artisan config:cache
I am currently creating an app with Laravel and Redis. Almost everything is working fine. I extended the Authentication as explained in the documentation, users can subscribe, login, logout ... I can create content and everything is stored in Redis.
But I have one issue. I can't run commands like "php artisan route:list", I have an error message : "[InvalidArgumentException] Database [redis] not configured.".
Th question is, is there anything special to do to make Artisan commands work when you set Redis as you database ? (basic configurations explained in the documention have been done and almost everything else is working fine).
Config:
In config/database.php I have:
return [
...
'default' => 'redis',
...
'redis' => [
'cluster' => false,
//'connection' => 'default',
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 7,
],
],
...
PS : You have the same error when you try to access the /password/email (password reset url).
InvalidArgumentException in DatabaseManager.php line 246:
Database [redis] not configured.
As Robert says in the comments, it looks like there is this error because there is no support for Redis as database for laravel.
I don't know why when I run a PHPUnit test, I get the following error:
PDOException: SQLSTATE[HY000] [2002] No such file or directory
My testing environment database setting is:
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'clg_test',
'username' => 'root',
'password' => 'veryHardPass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]
],
'migrations' => 'migrations',
];
The reason why I am using MySQL as oppose to SQLite is because my migration files use dropColumn which is not supported by SQLite. I call the migration via Artisan::call('migrate') in the setup.
If I actually call migration manually in the terminal via php artisan migrate --env=testing then the migration IS successful and the databases are created.
Why am I then facing the above problem?
Try changing localhost to 127.0.0.1. The message you're getting is indicative of the script not being able to connect to MySQL through a socket, but using an ip should work.
My website works, its clearly accessing the database. I can log in and i can create records, etc...
Ive created a new migration, and I'm trying to insert it, but when i run
php artisan migrate
i get the error
[PDOException]
SQLSTATE[HY000] [2002] Connection Refused
My database config has the passwords hidden in the environment so my config looks like this
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOSTNAME'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
my environment variables are loading correctly. What am i missing?
I figured it out. Apparently the environment that artisan was seeing was different from the environment i wanted it to see, so it was using the wrong host
php artisan migrate --env=production