我正在尝试进行迁移,但这给了我这个错误
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
添加stripe_id
varchar(255)null,添加card_brand
varchar(255)null,添加{ {1}} varchar(4)为空,请添加card_last_four
时间戳为空)
异常跟踪:
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
答案 0 :(得分:2)
Cashier附带了一些迁移,这些迁移会为您添加“客户列”到users
表中。
“收银员服务提供商注册了自己的数据库迁移目录,因此请记住在安装软件包后迁移数据库。收银员迁移会将几列添加到您的用户表,并创建一个新的订阅表可容纳您所有客户的订阅”
Laravel 6.x Docs - Cashier - Installation
因此,这些迁移尝试添加您自己添加的列。
“如果您想阻止Cashier的迁移完全运行,则可以使用Cashier提供的
ignoreMigrations
。”
答案 1 :(得分:1)
如果您使用的是laravel / cashier,它将为您添加收银员列和订阅表的迁移。因此,您不必为此编写单独的迁移。删除收银员列和订阅的迁移,然后尝试再次迁移。