Skip to content
Advertisement

I can’t add a column to a table with data in laravel

I’m doing this:

create:

php artisan make:migration add_total_invoice --table=invoices

Code:

public function up()
{
    Schema::table('invoices', function (Blueprint $table) {
        $table->double('total')->after('type');
    });
}

public function down()
{
    Schema::table('invoices', function (Blueprint $table) {
        $table->dropColumn('total');
    });
}
php artisan migrate

The migration runs without problems, but I am going to check the table and the column is not added, if I create a new migration and put a total to the new column, it says that the column already exists, what error is occurring?

Advertisement

Answer

go to the database table and delete the previous total column in the table and again go to the migration table and delete the last migration. then run php artisan migrate again

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement