اذهب إلى المحتوى
  • 0

معالجة الخطأ Foreign key constraint is incorrectly formed في Laravel

Mahmoud Alrashidi

السؤال

لا أعرف ما الذي يحدث مع المفتاح الثانوي الخاص بي ، لا يمكنني القيام بعملية التهجير كلما حاولت تنفيذ الأمر، يظهر لي خطأ

SQLSTATE[HY000]: General error: 1005 Can't create table abs-b2.articles (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table articles add constraint articles_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

هل هناك مُشكلة او خطأ ما أقوم به و كيف أحل المشكلة.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

يبدو يجب أن يكون حقل user_id من نوع unsignedBigInteger في جدول articles فيكون جدول users بهذا الشكل

Schema::create('users', function (Blueprint $table) {
    $table->id(); // unsignedBigInteger
    // other columns
});

و جدول articles 

Schema::table('articles', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...