سلام استاد، وقتتون بخیر
ببخشید یه سوال داشتم من کدهامو مشابه شما توی ویدیو زدم ولی وقتی migrate کردم به ارور زیر برخوردم:
SQLSTATE[HY000]: General error: 1005 Can't create table `shopDB`.`order_product` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `order_product` add constraint `order_product_order_id_foreign` foreign key (`order_id`) references `orders` (`id`) on delete cascade)
علاوه بر اینکه دوتا فیلد phone و address هم به جدول users اضافه نشدن، مشکل از چی هستش؟
کدهای مربوط به ادکردن فیلدها به جدول user + کد جدول order_prodcut رو هم براتون گذاشتم، ممنون میشم بررسی کنید بگید بهم کجا احیاناً اشتباهی رخ داده!
class AddPhoneNumberAndAddressIntoUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->char('phone_number')->nullable();
$table->string('address')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
}
public function up()
{
Schema::create('order_product', function (Blueprint $table) {
$table->bigInteger('order_id');
$table->bigInteger('product_id');
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->timestamps();
});
}