Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcmargentina's avatar

user saidthat both

                          <td>{{$intervention->client->user->nom}}</td>


                       <td>{{$intervention->technicien->user->nom}}</td>

worked but separated, and when they are together the app crashes .... crazy world

rin4ik's avatar

btw you have here typos closing /th twice

     <input type="date" class="light-table-filter" data-table="order-table" 
          placeholder="Filter" style="width: 120px;"></th></th>
                                <th type="date">Duré Prévu <br />
                                    <input type="date" class="light-table-filter" data-table="order-table" 
          placeholder="Filter" style="width: 180px;"></th></th>
chagouani's avatar

@jcmargentina @rin4ik think I have a relationship problem because I see it does not have a forein key with technician (it's not my fault it's the fault of my partner) errno: 150 "Foreign key constrain t is incorrectly formed"

Schema::create('interventions', function (Blueprint $table) {
        $table->increments('id');
        $table->date('date_intervention');
        $table->string('description');
        $table->dateTime('duree_prevu');
        $table->boolean('statut');
        $table->integer('technicien_id')->unsigned();
        $table->foreign('technicien_id')->references('id')->on('techniciens');
        $table->integer('tarification_id')->unsigned();
        $table->foreign('tarification_id')->references('id')->on('tarificationtaches');
        $table->integer('client_id')->unsigned();
        $table->foreign('client_id')->references('id')->on('client');


        $table->timestamps();
    });
jcmargentina's avatar
  • you tried to run the migration again? that is how you got that error ?

** did you try the "withDefault" code I gave you in every belongsTo and hasOne relationship involved on this ?

*** also ... do you have a lot of records in the interventions table?

can you please run this sql queries (in your sql editor) and compare the numbers of records returned ?

  1. select * from interventions , and get the number of records returned

  2. select * from interventions inner join techniciens on interventions.technicien_id = techniciens.id --> and compare the number of records returned

what I want to see are the results in pure SQL of the query with and without the relationship in interventions.

and do exactly the same BUT with the client relationship

chagouani's avatar

@jcmargentina I delete the entire database and restart the migration it gives me the previous error and in the database he did not add the index

jcmargentina's avatar
Level 8

probably ... you are getting the error because is trying to create a foreign key to a table that does not exists yet. When the migration fails ... check the database and see if the techniciens exists.

1 like
jcmargentina's avatar

delete the foreign instruction from the migration ... for now. so you can move on with the testing. Later you can manually add the foreign constraint from your SQL editor (Mysql workbench for example)

jcmargentina's avatar

delete all $table->foreign

for example:

$table->foreign('technicien_id')->references('id')->on('techniciens');

from migrations

rin4ik's avatar

try this please . you have already defined relations on model, you don't need to add constraint at all.

Schema::create('interventions', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('technicien_id')->unsigned(); 
        $table->integer('tarification_id')->unsigned(); 
        $table->integer('client_id')->unsigned(); 
        $table->date('date_intervention');
        $table->string('description');
        $table->dateTime('duree_prevu');
        $table->boolean('statut');
        $table->timestamps();
    });
Previous

Please or to participate in this conversation.