I was using sqlite and just tried to connect to my Mysql database by
changing the env.
php artisan migrate:fresh
Nothing Happened
Here's my .env:-
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=white
DB_USERNAME=root
DB_PASSWORD=
I tried deleting the sqlite file and now it shows me this error :- Database (/home/kabir/Desktop/White/database/database.sqlite) does not exist. (SQL: PRAGMA foreign_keys = ON;)
which is normal
Try clearing config and cache files.
In your terminal try
php artisan cache:clear
The solution to this situation is to run these commands:-
php artisan config:clear
php artisan cache:clear
Related
i am trying to migrate my first migration in laravel 7 project i have created database in phpmyadmin. i have Laragon app for localServer, these are my .env code for database connection
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=portfolio-project
DB_USERNAME=root
DB_PASSWORD=
when i do php artisan migrate it tells me that migrations are migrated, but when i go to phpmyadmin for checking tables it says no tables in this database,
Is there any problem with my phpmyadmin?
O any issue in new version 7 of laravel?
because when i added a phpmyadmin to laragon app there was issue with login password of phpmyadmin,
default password was not working and then i think i edit of its files to make no password at login on phpmyadmin after that i just type root as use and login it works, other old version laravel pakgs are working but this new version of laravel is making this issue at php artisan migrate
Make sure that every time you change your .env file you also do the following commands to clear any cache and make sure you are using the latest changes :
php artisan config:clear
php artisan cache:clear
Also make sure that root has no password and you can login to phpmyadmin without one.
First, close the server and the cmd and start it again then run the following command:
php artisan config:clear
Then run one of these commands:
php artisan migrate:fresh
or
php artisan migrate:refresh
It will drop all tables and recreate them again with the new migrations.
Hope it helps :)
I'm trying to create the migrations with laravel and i get this error:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = tutories and table_name = migrations and table_type = 'BASE TABLE')
at /Users/ivanortega/.bitnami/stackman/machines/xampp/volumes/root/htdocs/codi/UVIC/Tutories/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
/Users/ivanortega/.bitnami/stackman/machines/xampp/volumes/root/htdocs/codi/UVIC/Tutories/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:unix_socket=/var/mysql/mysql.sock;dbname=tutories", "root", "", [])
/Users/ivanortega/.bitnami/stackman/machines/xampp/volumes/root/htdocs/codi/UVIC/Tutories/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
I have tried to change the hostname, and the socket. Nothing works
This is my .env conf file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tutories
DB_USERNAME=root
DB_PASSWORD=
DB_SOCKET=/var/mysql/mysql.sock
I check that the socket exists, and I also create a link to /tmp/mysql.sock.
I change the php.ini file:
pdo_mysql.default_socket=/var/mysql/mysql.sock
Program versions:
XAMPP: 7.3.9
PHP: 7.3.6
MariaDB: 10.0.34
MAC:MacOS Mojave v10.14.6
Finally I fonund the solution, newest versions of xampp in macOS works with a virtual machine, so when I run the migrate it was taking the db on my computer, not in the local machine.
Downloading the last version without the virtual machine works!
here i have two solution
change in you .env file
DB_HOST=127.0.0.1
to
DB_HOST=localhost
and then run following command to clear config file
php artisan config:clear
second way to solved this issue is add following line in you .env file
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
FOR Mac OS, try to add the following line in your .env
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
I need your help again.
Is there a way to reset all configuration in MySQL?
Here's what happened. I previously have a project installed and this time I'm setting up a new one.
In this new project, I wanted to set it up with my a new database, new username I created and password. However, when I reached the point where I had to execute php artisan migrate, it keeps throwing me an error saying PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
If not that error, it's throwing connection refused instead.
Note: I'm using laradock.
Now, I'm at the point where I'd just rather reset the whole MySQL because I'm thinking it's conflicting with my previous configuration with my previous project.
As I searched online, I've tried the following:
1. Restarted server
2. Changed db_host from 127.0.0.1 to localhost and vice-versa
3. Added the project's directory to the dev environment setting
4. Docker-compose down and then up again
5. Even uninstalled and reinstalled docker itself
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=newdbname
DB_USERNAME=newusername
DB_PASSWORD=newpassword!
All I want is to be able to execute php artisan migrate using the new credentials I set.
If you really do not need any old data in database, you can just delete them & reset up a container:
# stop mysql service
docker-compose stop mysql
# delete old mysql database
rm -rf ~/.laradock/data/mysql
# resetup mysql container
docker-compose up -d nginx mysql
You can get the mysql database location according to docker-compose.yml & env-example:
docker-compose.yml:
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql
env-example:
DATA_PATH_HOST=~/.laradock/data
I've dropped my test database then I want to create new database using saved migrations:
2017_03_01_000000_create_api_table.php
2017_03_06_000000_create_beeline_calls.php
2017_03_13_000000_modify_beeline_emails.php
2017_03_14_000000_interactive_forms.php
2017_03_16_000000_model_instances.php
2017_03_24_000000_create_objects.php
2017_03_24_000001_create_objects_tables_v2.php
2017_03_24_000003_make_comments_without_users.php
2017_03_27_000000_add_processed_to_announcements.php
2017_03_29_000000_create_ads_channels.php
2017_03_29_000001_announcement_client.php
2017_04_06_000000_create_filters.php
2017_04_07_000000_create_new_input_types.php
When I run php artisan migrate --pretend
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'creator_id' on table 'application_model_instance_announcement_comments'.
But first migration file to run is 2017_03_01_000000_create_api_table.php
Why does it run not from start? Database is empty, migrations table is empty.
As I understand Laravel should run migration files in alphabetical order.
To be able to perform php artisan migrate that table where you are creating the columns can't contain the same column names as in that migration. You must delete it first and with this command
php artisan migrate:refresh
you are doing exactly this
php artisan migrate:rollback
php artisan migrate
There are 2 commands in php artisan migrate:refresh
When changing something in migrations always run these commands:
php artisan cache:clear
php artisan view:clear
php artisan route:clear
composer dump-autoload
It will clear all old stuff and should run smoothly!
So I am using my cmd on my laravel folder and I tried to do (php artisan migrate:install). 2 errors came up.
[PDOException] SQLSTATE[HY000] [2006] MySQL server has gone away
[ErrorException] PDO::__construct(): MySQL server has gone away
Can anyone please explain what I did wrong?
You have Lost SQL connection to server during query. It is temporally issue. This is because of very low default setting of max_allowed_packet.
Raising max_allowed_packet in my.cnf (under [mysqld]) to 8 or 16M usually fixes it.
[mysqld]
max_allowed_packet=16M
NOTE: This can be set on your server as it's running. You need to restart the MySQL service once you are done.
Use: set global max_allowed_packet=104857600. My value sets it to 100MB.
This is not a Laravel issue, but a general MySQL Issue. Maybe the server is not running. Are you sure you're running MySQL in the background?
Check this link: MySQL Gone Away
Do the following checks in your system:
The Database Engine is running
You have created your database
You have created an user and granted permissions to the database
You have setup the user and the database in your Laravel's .env file.
After this, try to run the migrations command again, which is:
php artisan migrate
As explained Here
Let us know if that helps :).
For me the problem seemed to be that I assigned the wrong port to my Laravel project's .env file. Later, when I matched it with the my.cnf file, it worked.
I'm using Ubuntu 16.04 + nginx + MariaDB + Laravel project.
I encountered the same problem. The solution was to delete the mysql port number from 3306 or 80, and leave it empty
In files
.env DB_PORT=3306 to DB_PORT=
and on
database.php 'port' => env('DB_PORT', '3306'), to 'port' => env('DB_PORT', ''),
In my case the problem was I changed DB_HOST to localhost but it was fixed by keeping it default ie 127.0.0.1 and the port to default 3306.
Here is the configuration for localhost in xampp:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hmb
DB_USERNAME=root
DB_PASSWORD=
Although I use localhost:8081/phpmyadmin to access my db
In addition to other answers:
Try changing localhost domain to 127.0.0.1 both in .env and config/database.php.
Also If you're using git then check git status and see if any unwanted files have been changed.
Because In my case options array for mysql connection configuration in file config/database.php was blank array somehow. I checked out git checkout config/database.php file and it starting to work fine.
If someone is looking for a solution, try to clean all cache you have, you can manually delete cache files in bootstrap/cache folder.
My solution is due to fix the DB_HOST parameter. Indeed I use PHPStorm and I set the public url in .env in order to use DB tools from the IDE and this broken Laravel.
So I changed DB_HOST to localhost and Laravel now works fine.