mardi 30 janvier 2018

Laravel foreign key creation fails

I am using laravel 5.4. I want to create relationship with two table. one is users table and another is sir table. users table is already created. here is my sir table migration code

public function up()
{
    Schema::create('sir', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users');
        $table->timestamps();
    });
}
public function down()
{
    Schema::dropIfExists('sir');
}

now when I try to migrate it shows me this error

`  SQLSTATE[HY000]: General error: 1005 Can't create table 
`finalproject`.`#sq
l-9cc_98` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL:
alter table `available_sir` add constraint `available_sir_user_id_foreign`
foreign key (`user_id`) references `users` (`id`))`

I have followed some tutorial but those are not working and also tried with laravel documentation, but still it is not working. anyone please help me to find a solution for this. thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DLYN8m
via IFTTT

Aucun commentaire:

Enregistrer un commentaire