1

I want to create a relation between the users-table and my other tabe in php laravel. After migrating this with the command:

  • php artisan migrate:fresh --seed

nothing happens

The migration file:

$table
    ->unsignedBigInteger('updated_from')
    ->nullable()
    ->foreign('updated_from')
    ->references('id')
    ->on('users');

And after refreshing the erd in datagrip there is no relation between the two tables: enter image description here

There is no relation. The other arrow comes from another table.

stevan06
  • 57
  • 4
  • Take a look here: https://stackoverflow.com/questions/63617385/laravel-migrations-are-migrating-successfully-but-they-are-not-creating-foreign, and by the way, you can use `-> foreignId('update_from')` as helper – Vincent Decaux Aug 25 '23 at 09:51

1 Answers1

1

Have you tried with explicit foreign key:

$table->unsignedBigInteger('updated_from')->nullable();
$table->foreign('updated_from')->references('id')->on('users');
MorganFreeFarm
  • 3,811
  • 8
  • 23
  • 46