درود بنده مفهوم این باگ متوجه نمی شم من اومدم با دستور
php artisan make:migration add_field_kindofproduct_to_product --table=products
یک فیلد یعنی فیلد
Schema::table('products', function (Blueprint $table) { $table->unsignedBigInteger('kindofproduct'); $table->foreign('kindofproduct')->references('id')->on('kindofproducts')->onDelete('cascade'); });
به ادامه جدول products اضافه کنم
که وقتی rollback می کنم با ارور زیر مواجه میشم
Rolling back: 2021_11_15_110528_add_field_kindofproduct_to_product Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 1553 Cannot drop index 'products_kindofproduct_foreign': needed in a foreign key constraint (SQL: alter table `products` drop `ki ndofproduct`) at C:\Users\AsemaN\Desktop\AryaBMS\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:\Users\AsemaN\Desktop\AryaBMS\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485 PDOException::("SQLSTATE[HY000]: General error: 1553 Cannot drop index 'products_kindofproduct_foreign': needed in a foreign key constraint") 2 C:\Users\AsemaN\Desktop\AryaBMS\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485 PDOStatement::execute()
این رو هم اضافه کنم که جدول دیگم که می خوام روابط یک به چند بین محصول و نوع محصول ایجاد بشه این هست
public function up() { Schema::create('kindofproducts', function (Blueprint $table) { $table->id(); $table->string('type'); $table->timestamps(); }); }
متد down مدل product رو به این شکل در بیارید:
public function down() { Schema::table('products', function (Blueprint $table) { $table->dropForeign(['kindofproduct']); $table->dropColumn('kindofproduct'); }); }
@websaz درود
این متد down فیلد اضافه جدول product
public function down() { Schema::table('products', function (Blueprint $table) { $table->dropColumn('kindofproduct'); }); }
و اینم متد down جدول kindofproducts
public function down() { Schema::dropIfExists('kindofproducts'); }
متد down مدل product رو به این شکل در بیارید:
public function down() { Schema::table('products', function (Blueprint $table) { $table->dropForeign(['kindofproduct']); $table->dropColumn('kindofproduct'); }); }
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟