vendredi 27 octobre 2017

cannot find DB connection info

I checked my config/database.php

I have:

 'default' => env('DB_CONNECTION', 'mysql'),

and in my connection I have:

 'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,

but it seems that my DB configuration areh happening somewhere elese, I also defined my varioables in my .env file. But when I run the migrate in my app directory, it errors out :

[Illuminate\Database\QueryException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'usernam e' (SQL: alter table users add username varchar(191) null)

although I have already taken the migrate file for users out (renamed the php extension of it)

Any help will be appreciated.

edit: does thi happen that migration files are stored somewhere other than /database/migrations ?



via Chebli Mohamed

1 commentaire:

  1. Hey guy, maybe this problem is in some search you did with some join.

    i resolved this problem. In my case I was making a join and I had both the user ID in one table and the other, which defined this binding between both tables, so what I did was select only the columns I really needed, eliminating which was duplicated just as the message says, so I solved the problem, so was my solution:

    ```
    $queryBuilder = DB::table('tab_pontuacoes_secretarias')
    ->whereNull('tab_pontuacoes_secretarias.deleted_at')
    ->leftJoin('tab_secretarias', function($query)
    {
    $query->on('tab_pontuacoes_secretarias.secretaria_id', '=', 'tab_secretarias.id');
    })
    ->select(
    'tab_secretarias.nome',
    'tab_secretarias.med_id',
    'tab_secretarias.id',
    'tab_pontuacoes_secretarias.id',
    'tab_pontuacoes_secretarias.descricao',
    'tab_pontuacoes_secretarias.data',
    'tab_pontuacoes_secretarias.pontos',
    'tab_pontuacoes_secretarias.deleted_at',
    tab_pontuacoes_secretarias.'secretaria_id'
    )
    ->orderBy('data', 'desc');
    ```

    Use the select option to select the columns you need ...

    RépondreSupprimer