2
votes

I am trying to do this migration but it gives me this error

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');
    }
    }

and give me this error

Column already exists: 1060 Duplicate column name '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)

Exception trace:

1 PDOException::("SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name '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

2
Have you tried to php artisan migrate:fresh?Lucas Arbex
Why does it give me a feeling that you have shown the wrong migration file?Vagabond
yes but the problem continuesAdrian Galindo Gallardo

2 Answers

2
votes

Cashier comes with migrations that add the "customer columns" to the users table for you.

"The Cashier service provider registers its own database migration directory, so remember to migrate your database after installing the package. The Cashier migrations will add several columns to your users table as well as create a new subscriptions table to hold all of your customer's subscriptions"

Laravel 6.x Docs - Cashier - Installation

So these migrations are trying to add a column that you have added yourself.

"If you would like to prevent Cashier's migrations from running entirely, you may use the ignoreMigrations provided by Cashier."

1
votes

If you are using the laravel/cashier, it will add the migration for the cashier columns and the subscription table for you. So you don't have to write seperate migration for this. Remove the migration for the cashier columns and subscription and try to migrate again.