SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "car_products" already exists (SQL: create table "car_products" ("car_id" integer not null, "product_id" integer not null))
nnk-maker opened this issue · 0 comments
Hi,
I am at 5:45. I tried to create an image_path column but facing some issues .
to come out that issue, I try to run the php artisan migrate:rollback. But now i strucked in the table creating can some help me to come out of these issue. If require i can commit my code in the github as well.
php artisan migrate:fresh
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
Dropped all tables successfully.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (32.45ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (16.87ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (27.59ms)
Migrating: 2021_07_13_193955_create_cars_table
Migrated: 2021_07_13_193955_create_cars_table (37.96ms)
Migrating: 2021_07_18_213642_create_engines_table
Migrated: 2021_07_18_213642_create_engines_table (17.53ms)
Migrating: 2021_07_19_210643_create_car_production_dates_table
Migrated: 2021_07_19_210643_create_car_production_dates_table (18.20ms)
Migrating: 2021_07_20_214007_create_products_table
Migrated: 2021_07_20_214007_create_products_table (12.84ms)
Migrating: 2021_07_20_214653_create_car_products_table
Illuminate\Database\QueryException
SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "car_products" already exists (SQL: create table "car_products" ("car_id" integer not null, "product_id" integer not null))
at C:\cars\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692
688▕ // If an exception occurs when attempting to run a query, we'll format the error
689▕ // message to include the bindings with SQL, which will make this exception a
690▕ // lot more helpful to the developer instead of just the database's errors.
691▕ catch (Exception $e) {
➜ 692▕ throw new QueryException(
693▕ $query, $this->prepareBindings($bindings), $e
694▕ );
695▕ }
696▕
1 C:\cars\cars\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485
PDOException::("SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "car_products" already exists")
2 C:\cars\cars\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485
PDOStatement::execute()
Below is my 2014_10_12_000000_create_users_table
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
2014_10_12_100000_create_password_resets_table
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
2019_08_19_000000_create_failed_jobs_table
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
2021_07_13_193955_create_cars_table
public function up()
{
Schema::create('cars', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('founded');
$table->longText('description');
$table->timestamps();
});
Schema::create('cars_models', function (Blueprint $table) {
$table -> increments('id');
$table -> unsignedInteger('car_id');
$table -> string('model_name');
$table -> timestamps();
$table -> foreign('car_id')
-> references('id')
-> on('cars')
-> onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cars');
}
2021_07_18_213642_create_engines_table
public function up()
{
Schema::create('engines', function (Blueprint $table) {
$table -> increments('id');
$table -> unsignedInteger('model_id');
$table -> string('engine_name');
$table -> timestamps();
$table -> foreign('model_id')
-> references('id')
-> on('cars_models')
-> onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('engines');
}
2021_07_19_210643_create_car_production_dates_table
public function up()
{
Schema::create('car_production_dates', function (Blueprint $table) {
$table -> id('id');
$table -> unsignedInteger('model_id');
$table -> date('created_at');
$table -> foreign('model_id')
-> references('id')
-> on('cars_models')
-> onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('car_production_dates');
}
2021_07_20_214007_create_products_table
public function up()
{
Schema::create('car_products', function (Blueprint $table) {
$table -> increments('id');
$table -> string('name');
$table -> timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
Below is my 2021_07_20_214653_create_car_products_table.php
public function up()
{
Schema::create('car_products', function (Blueprint $table) {
$table->integer('car_id')->unsigned();
$table->integer('product_id')->unsigned();
$table->foreign('car_id')
->references('id')
->on('cars')
->onDelete('cascade');
$table->foreign('product_id')
->references('id')
->on('products')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('car_products');
}
Below is my 2021_07_24_092123_add_image_to_cars_table.php
public function up()
{
Schema::table('cars', function (Blueprint $table) {
$table->string('image_path');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('cars', function (Blueprint $table) {
$table->dropColumn('image_path');
});
}