Home > Enterprise >  I have an error after using php artisan migrate
I have an error after using php artisan migrate

Time:09-15

Here is the message I got after the migration.

Illuminate\Database\QueryException

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

The errors are both in line 70, which is

/**
 * Create a new PDO connection instance.
 *
 * @param  string  $dsn
 * @param  string  $username
 * @param  string  $password
 * @param  array  $options
 * @return \PDO
 */
protected function createPdoConnection($dsn, $username, $password, $options)
{
    if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
        return new PDOConnection($dsn, $username, $password, $options);
    }

    return new PDO($dsn, $username, $password, $options);
}

Line 70 is the return new PDO($dsn, $username, $password, $options);

The first error was PDOException::("SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.")

and the second error was PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=econnect", "root", "", [])

UPDATE

I made a mistake to not start the MYSQL and APACHE on XAMP, after I started it, it worked but there is another error occured which is

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'personal_access_tokens' already exists (SQL: create table personal_access_tokens (id bigint unsigned not null auto_increment primary key, tokenable_type varchar(255) not null, tokenable_id bigint unsigned not null, name varchar(255) not null, token varchar(64) not null, abilities text null, last_used_at timestamp null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

I have 5 migrations files, but here is where the "personal_access_tokens" table

    <?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePersonalAccessTokensTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('personal_access_tokens', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->morphs('tokenable');
            $table->string('name');
            $table->string('token', 64)->unique();
            $table->text('abilities')->nullable();
            $table->timestamp('last_used_at')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('personal_access_tokens');
    }
}

CodePudding user response:

Try to check if the services is active (Mysql, apache/nginx) etc.

CodePudding user response:

Are you able to connect to this database via any mysql client? It may be a configuration issue on mysql server, typo, or you shouldn't use root user.

If you're using laradock, try to change in .env file from:

DB_CONNECTION=127.0.0.1

to:

DB_CONNECTION=mysql
  • Related