#Migration error

13 messages · Page 1 of 1 (latest)

slate wagon
#

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('pizza_product', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('pizza_id');
            $table->unsignedBigInteger('product_id');
            $table->timestamps();

            // Define foreign keys with onDelete('cascade')
            $table->foreign('pizza_id')->references('id')->on('pizzas')->onDelete('cascade');

            $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('pizza_product');
    }
};

The error : 
   Illuminate\Database\QueryException 

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'pizza_product' already exists (Connection: mysql, SQL: create table `pizza_product` (`id` bigint unsigned not null auto_increment primary key, `pizza_id` bigint unsigned not null, `product_id` bigint unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:822
    818$this->getName(), $query, $this->prepareBindings($bindings), $e
    819▕                 );
    820▕             }
    821▕
  ➜ 822throw new QueryException(
    823$this->getName(), $query, $this->prepareBindings($bindings), $e
    824▕             );
    825▕         }
    826▕     }

  1   vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
      PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'pizza_product' already exists")

  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
      PDOStatement::execute()
#

I am having some errors with this migration

wheat wyvern
#

Base table or view already exists: 1050 Table 'pizza_product' already exists
the table already exists, guess you have run the migration twice?

slate wagon
#

i ran with

#

php artisan migrate:refresh

#

within the complete project it is mentioned twice and it's the same migration

wheat wyvern
wheat wyvern
slate wagon
#

Yes

wheat wyvern
wheat wyvern
slate wagon
#

Yes it is

#

Just a school project