laravel - Laravel Column 已经存在:1060 Duplicate column name
问题描述
我正在尝试进行此迁移,但它给了我这个错误
enter code here
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
public function up()
{
//CREANDO UN MODELO PARA LOS ROLES DEL USUARIO
Schema::create('roles', function (Blueprint $table) {
$table->Increments('id');
$table->string('name')->comment('Nombre del rol del usuario');
$table->text('description');
$table->timestamps();
});
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('role_id')->default(\App\Role::STUDENT);
$table->foreign('role_id')->references('id')-> on('roles');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('picture')->nullable();
//cashier columns
$table->string('stripe_id')->nullable();
$table->string('card_brand')->nullable();
$table->string('card_last_four', 4)->nullable();
$table->timestamp('trial_ends_at')->nullable();
$table->rememberToken();
$table->timestamps();
});
Schema::create('subscriptions',function (Blueprint $table) {
$table->increments('id');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->string('name');
$table->string('stripe_status');
$table->string('stripe_plan');
$table->integer('quantity');
$table->timestamp('trial_ends_at')->nullable();
$table->timestamp('ends_at')->nullable();
$table->timestamps();
});
Schema::create('user_social_accounts', function (Blueprint $table) {
$table->increments('id');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')-> on('users');
$table->string('provider');
$table->string('provider_uid');
});
}
public function down()
{
Schema::dropIfExists('users');
Schema::dropIfExists('roles');
Schema::dropIfExists('subscriptions');
Schema::dropIfExists('user_social_accounts');
}
}
并给我这个错误
列已存在:1060 列名重复“stripe_id”(SQL:alter table users
add stripe_id
varchar(255) null,add card_brand
varchar(255) null,add card_last_four
varchar(4) null,add trial_ends_at
timestamp null)
异常跟踪:
1 PDOException::("SQLSTATE[42S21]: 列已经存在:1060 列名重复'stripe_id'") C:\laragon\www\learning\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459
2 PDOStatement::execute() C:\laragon\www\learning\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459
解决方案
Cashier 带有迁移功能,可以为您将“客户列”添加到users
表中。
“Cashier 服务提供商注册了自己的数据库迁移目录,因此请记住在安装软件包后迁移您的数据库。Cashier 迁移会在您的用户表中添加几列,并创建一个新的订阅表来保存您所有客户的订阅”
因此,这些迁移正在尝试添加您自己添加的列。
“如果您想阻止 Cashier 的迁移完全运行,您可以使用
ignoreMigrations
Cashier 提供的。”
推荐阅读
- polymer - 通过 querySelectorAll() 获取节点列表
- python - asyncio call_later 中的 lambda
- javascript - 将javascript模板输出到行div内的html页面
- matlab - 如何从 Scaramuzza 全向相机校准工具箱中消除未失真全景图像的底部失真?
- javascript - How to output a variable in a javascript function to text in html
- sql - 使用变量时 SQL LIKE 不同的输出
- c++ - CGAL Alpha Iterator Segmentation Fault(基于 alpha shape 3D 示例)
- typescript - 续集更新不接受`null`作为打字稿的属性
- eclipse - Eclipse:多个项目设置窗口
- sql-server - MsSQL 触发器未针对多个插入运行