ali_254 Posted June 5, 2021 Share Posted June 5, 2021 hi ... I made a table called: flights , Also, I want to create another table and run the "join" operation between them. this table called: flight_comments table flights: public function up() { Schema::create('flights', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); table flight_comments: public function up() { Schema::create('flight_comments', function (Blueprint $table) { $table->bigIncrements('id'); $table->bigInteger('flight_id')->unsigned(); $table->string('body','140'); $table->nullabletimestamps(); $table->foreign('flight_id')->references('id')->on('flights')->onDelete('cascade'); }); } When I run the "migration" command, I get the following error: In Connection.php line 647: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `flight_comments` add constraint `flight_ comments_flight_id_foreign` foreign key (`flight_id`) references `flights` (`id`) on delete cascade) In Connection.php line 449: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint please guide me Quote Link to comment Share on other sites More sharing options...
Barand Posted June 5, 2021 Share Posted June 5, 2021 Is the column UNSIGNED in both tables? 1 Quote Link to comment Share on other sites More sharing options...
ali_254 Posted June 5, 2021 Author Share Posted June 5, 2021 1 hour ago, Barand said: Is the column UNSIGNED in both tables? no , only in table flights Quote Link to comment Share on other sites More sharing options...
Barand Posted June 5, 2021 Share Posted June 5, 2021 That was intended as a hint. Make them both the same and you should then be able to create your foreign key. 1 Quote Link to comment Share on other sites More sharing options...
ali_254 Posted June 5, 2021 Author Share Posted June 5, 2021 2 minutes ago, Barand said: That was intended as a hint. Make them both the same and you should then be able to create your foreign key. thanks , but i delete all table in phpmyadmin and Reinstall the code "php artisan migrate" , Problem solved, thanks a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.