سلام ببخشید من یه مشکلی برام پیش اومد نتونستم جوابی که در تاپیک قبلی دادید رو پاسخ بدم و حالا اون بسته شده و دیگه مجبور شدم یکی جدید باز کنم!
اون چیزی که گفتید تغییر بدم داخل تاپیک https://7learn.com/app/topics/12883 رو لحاظ کردم ولی بازم به همون ارور قبلی میخورم.
طبق چیزی که نوشته میگه foreign key من اشتباهه ولی ...
use Illuminate\\Database\\Migrations\\Migration;
use Illuminate\\Database\\Schema\\Blueprint;
use Illuminate\\Support\\Facades\\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->char('title');
$table->text('description');
$table->char('thumbnail_url');
$table->char('demo_url');
$table->char('source_url');
$table->unsignedInteger('price');
$table->unsignedBigInteger('category_id');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->unsignedBigInteger('owner_id');
$table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
};
##################################################################### TERMINAL ############################################################################
SQLSTATE[HY000]: General error: 1005 Can't create table `7gallery`.`products` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `products` add constraint `products_category_id_foreign` foreign key (`category_id`) references `categories` (`id`) on delete cascade)
at C:\\xampp\\htdocs\\7gallery.php\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:759
755▕ // If an exception occurs when attempting to run a query, we'll format the error
756▕ // message to include the bindings with SQL, which will make this exception a
757▕ // lot more helpful to the developer instead of just the database's errors.
758▕ catch (Exception $e) {
➜ 759▕ throw new QueryException(
760▕ $query, $this->prepareBindings($bindings), $e
761▕ );
762▕ }
763▕ }
1 C:\\xampp\\htdocs\\7gallery.php\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:544
PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `7gallery`.`products` (errno: 150 "Foreign key constraint is incorrectly formed")")
2 C:\\xampp\\htdocs\\7gallery.php\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:544
PDOStatement::execute()