Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #394
    dan
    Participant

    SQLSTATE[HY000]: General error: 1005 Can’t create table laravel.questions (errno: 150 “Foreign key constraint is incorrectly formed”) (Connection: mysql, SQL: alter table questions add constraint questions_subject_id_foreign foreign key (subject_id) references subjects (id) on delete cascade)

    #395

    So in your database/migrations folder my guess is that your migrations files is arranged like this:

    create_questions_table.php
    create_subjects_table.php

    When you run php artisan migrate

    You questions migration file will look for the foreign key subject_id but it does not exist yet because it will still be created after your questions table

    Just interchange the sequence of your file in database/migrations folder like this

    create_subjects_table.php
    create_questions_table.php

    How you can delete create_questions_table.php file and then create that file again in the command prompt
    php artisan make:table create_questions_table and it will position below create_subjects_table.php

    #397
    dan
    Participant

    You are right! Thank you

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.