0

When run migrate command the following error is displaying

    [Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'SSA_DATA.#sql-431_1b8' (errno: 150) (SQL: alter table `reports_fields` add constraint rep  
  orts_fields_report_id_foreign foreign key (`report_id`) references `reports_list` (`id`))      

migration code is below

 public function up()
 {
     Schema::create('reports_fields', function(Blueprint $table)
     {
         $table->increments('id');
         $table->smallInteger('report_id')->unsigned();
         $table->smallInteger('field_id')->unsigned();
     });

     Schema::table('reports_fields', function($table) 
     {
         $table->foreign('report_id')->references('id')->on('reports_list');
     });
 }

 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop('reports_fields');
 }

What is the reason for this ?

errakeshpd
  • 2,544
  • 2
  • 28
  • 35
  • Are you sure your database user has the privileges to `ALTER` tables? – Samuel Cook Jan 03 '15 at 16:07
  • @SamuelCook I created many table using (migration files) without the foreign key reference. – errakeshpd Jan 03 '15 at 16:09
  • Please use the search before asking a question. Error number 150 should not only be well explained in the documentation of the database server you use, but also with many comments in popular developer resources next to the vendors website, like - let's say - the duplicate question on stackoverflow I closed yours against. Thank you. – hakre Jan 03 '15 at 16:11

0 Answers0