【发布时间】:2021-11-03 08:15:19
【问题描述】:
我正在尝试编辑现有项目,我添加了一些 php artisan migrations,当我尝试 php artisan migrate 或 php artisan schema:dump 时,它一直显示此错误消息,我尝试了 composer update 和 composer require doctrine/dbal 以及我的 @ 987654326@看起来像这样
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
在终端中显示这样的错误请任何人建议我解决这个问题
Illuminate\Database\QueryException
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:\Users\Crazymhegde\Downloads\Admin Install\vendor\laravel\framework\src\Illuminate\Database\Connection.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:\Users\Crazymhegde\Downloads\Admin Install\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485
PDOException::("SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'cm_firebase_token'")
2 C:\Users\Crazymhegde\Downloads\Admin Install\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485
PDOStatement::execute()
这个错误显示的代码在这里我添加了它所需的一切
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
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');
});
}
}
【问题讨论】:
-
错误告诉你:你尝试创建的列已经存在
-
如果我删除或删除此迁移是否可以正常工作/有任何问题
-
您之前可能已经运行过迁移并且没有执行
php artisan migrate:rollback来撤消更改,尽管迁移表现在似乎不同步,所以请手动删除该列
标签: php mysql laravel laravel-8