jeudi 23 février 2017

Unable to add foreign key in Laravel

In a laravel migration file I have the following code:

   Schema::table('stripe_customers', function (Blueprint $table) {
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
   });

'user_id' is an existing unsigned integer column in the table 'stripe_customers'.

'id' is a primary key column in 'users'.

However when I run the migrate command I get the following error message:

  [Illuminate\Database\QueryException]                                                                      
  SQLSTATE[HY000]: General error: 1005 Can't create table 'thedealerapp.#sql-47a_78859' (errno: 150) (SQL:  
   alter table `stripe_customers` add constraint stripe_customers_user_id_foreign foreign key (`user_id`)   
  references `users` (`id`))                                                                                

  [PDOException]                                                                                      
  SQLSTATE[HY000]: General error: 1005 Can't create table 'thedealerapp.#sql-47a_78859' (errno: 150)  

Why is this happening?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire