Skip to content
Advertisement

I Can’t show my database tables through migration command on powershell terminal (Windows 10)

I tried to run: php artisan migrate

Also to connect to MySQL using terminal on Windows.

I Got this error:

  SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it (SQL: select * from information_schema.tables where table_schema = firstproject and table_name = migrations and table_type = 'BASE TABLE')

  at C:UsersekindDesktopLaravelTestFirstProjectvendorlaravelframeworksrcIlluminateDatabaseConnection.php:692
    688▕         // If an exception occurs when attempting to run a query, we'll format the error
    689▕         // message to include the bindings with SQL, which will make this exception a
    690▕         // lot more helpful to the developer instead of just the database's errors.
    691▕         catch (Exception $e) {
  ➜ 692▕             throw new QueryException(
    693▕                 $query, $this->prepareBindings($bindings), $e
    694▕             );
    695▕         }
    696▕     }

  1   C:UsersekindDesktopLaravelTestFirstProjectvendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70
      PDOException::("SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it")

  2   C:UsersekindDesktopLaravelTestFirstProjectvendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70
      PDO::__construct()

.env file:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306          
DB_DATABASE=firstprojectdb      
DB_USERNAME=root  
DB_PASSWORD=Ekin1234

I tried to change my DB_HOST to “localhost” but it didn’t work.

When I want to show databases it shows those;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| firstproject       |
| firstprojectdb     |
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+

But even if I create tables like these it didn’t see

public function up()

{
    Schema::create('posts', function (Blueprint $table) {
        $table->increments('id'); // İdentity(1,1) İd int
        $table->string('title');  // title (Create a new string column on the table.)
        $table->mediumText('body'); // body  (Create a new medium text column on the table.)
        $table->timestamps();
    });

As you see;

mysql> show tables;
Empty set (0.00 sec)

I even delete the extension of “extension=pdo_mysql” but it didn’t work to me.

PLS HELP ME GUYS

Advertisement

Answer

Try to make sure that your server is running, if you are working on the localhost check your Xampp that the server and mysql both are running. see image here make sure these are not stopped like this First run: php artisan migrate and then if you get the error check your .env, that you have provided the correct details or not.

Note: localhost by default have no password, make sure that you have the same password and database name.

Furthermore, if the above doesn’t work for you then try the below commands:

php artisan config:cache

and then:

php artisan migrate
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement