skip to Main Content

I I’m trying to edit existing project i added some php artisan migrations and when im trying to php artisan migrate or php artisan schema:dump it is keep showing this error message i tried composer update and composer require doctrine/dbal and also my .env looks like this

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:/NC6CNBiDJb2vV4fRviEsMqy5gKbePRgk44JGkZFAYY=
APP_DEBUG=true
APP_URL=http://localhost
APP_MODE=dev

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=phpmyadmin
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
SOFTWARE_ID=MzM1NzE3NTA=
BUYER_USERNAME=tt
PURCHASE_CODE=fsgf

error shows like this in the terminal please anyone suggest me to solve this issue

IlluminateDatabaseQueryException

SQLSTATE[42S21]:  Column already exists: 1060 Duplicate column name 'cm_firebase_token'(SQL: alter table `users` add `cm_firebase_token` varchar(191) null)

  at C:UsersCrazymhegdeDownloadsAdmin InstallvendorlaravelframeworksrcIlluminateDatabaseConnection.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:UsersCrazymhegdeDownloadsAdmin InstallvendorlaravelframeworksrcIlluminateDatabaseConnection.php:485
      PDOException::("SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'cm_firebase_token'")

  2   C:UsersCrazymhegdeDownloadsAdmin InstallvendorlaravelframeworksrcIlluminateDatabaseConnection.php:485
      PDOStatement::execute()

and my code which this error shows to is here i added everything it required

<?php

use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;

class AddCmFirebaseTokenColumnToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('cm_firebase_token')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('cm_firebase_token');
        });
    }
}

2

Answers


  1. Column name cm_firebase_token alredy exist in table. It looks like you created the migration after you manually added the column into table.

    Just copy the migration file name and insert it into migrations table.

    Login or Signup to reply.
  2. you shoould use php artisan migrate:fresh command to renew your database

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search