Support the ongoing development of Laravel.io →
Requests Database Eloquent

I created two tables and wanted to use the following command to create a foreign key $table->foreign('users_id')->references( ' id')->on(' users' ); And is giving me a Generar error:1215 , failed to add foreign key constraint what did i do wrong

Last updated 3 years ago.
0

Are you referencing an existing key? And is that key of the same type? int? nullable? signed?

0

You have a space before 'id' btw, if you literally copied this that is probably your problem.

0

users_id is present on the table?

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

igbostick igbostick Joined 23 May 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.