![Laravel Advance | How to Add Foreign Key in Laravel Migration | by Raviya Technical | Raviya Technical | Medium Laravel Advance | How to Add Foreign Key in Laravel Migration | by Raviya Technical | Raviya Technical | Medium](https://miro.medium.com/max/1106/1*Z0YnCyGvpg5c3F3lUdjFjw.png)
Laravel Advance | How to Add Foreign Key in Laravel Migration | by Raviya Technical | Raviya Technical | Medium
![SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint · Issue #27717 · laravel/framework · GitHub SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint · Issue #27717 · laravel/framework · GitHub](https://user-images.githubusercontent.com/15104894/61328729-b9c16f00-a82c-11e9-8284-98f4ce43c6e4.png)
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint · Issue #27717 · laravel/framework · GitHub
![这种写法有点不懂:$table->foreign ('user_id')->references ('id')->on ('users')->onDelete ('cascade')? | Laravel | Laravel China 社区 这种写法有点不懂:$table->foreign ('user_id')->references ('id')->on ('users')->onDelete ('cascade')? | Laravel | Laravel China 社区](https://cdn.learnku.com/uploads/images/202004/16/12860/ncu9Q27mfE.png!large)
这种写法有点不懂:$table->foreign ('user_id')->references ('id')->on ('users')->onDelete ('cascade')? | Laravel | Laravel China 社区
![Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint - Qiita Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint - Qiita](https://qiita-user-contents.imgix.net/https%3A%2F%2Fcdn.qiita.com%2Fassets%2Fpublic%2Farticle-ogp-background-9f5428127621718a910c8b63951390ad.png?ixlib=rb-4.0.0&w=1200&mark64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTkxNiZ0eHQ9SWxsdW1pbmF0ZSU1Q0RhdGFiYXNlJTVDUXVlcnlFeGNlcHRpb24lMjAlMjAlM0ElMjBTUUxTVEFURSU1QkhZMDAwJTVEJTNBJTIwR2VuZXJhbCUyMGVycm9yJTNBJTIwMzc4MCUyMFJlZmVyZW5jaW5nJTIwY29sdW1uJTIwJTI3dXNlcl9pZCUyNyUyMGFuZCUyMHJlJUUyJTgwJUE2JnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmdHh0LWNsaXA9ZWxsaXBzaXMmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz01ZGU0NzAwMDY5OTk3NTFhMDA4YWY5MzM5ZTFkMGExYQ&mark-x=142&mark-y=112&blend64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTYxNiZ0eHQ9JTQweW9zaGlueWFuJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9MzYmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz1mZjY2NDgyNjA1MTliNTA4OThmMDVjM2Q4NjM5YzM3YQ&blend-x=142&blend-y=491&blend-mode=normal&s=92353de95cf744313f54dc3f63cda371)